struts2 学习记录
来源:互联网 发布:淘宝客什么平台推广大 编辑:程序博客网 时间:2024/06/11 18:51
1、在jsp中加上<s:debug/>会有意想不到的结果;
如果加入了struts2-dojo-plugin.***.jar在浏览器用get方式传debug=console时会弹出一个调试控制台,IE无效;
如果加入了struts2-config-browser-plugin后,在浏览器用get方式传debug=browser之后,也会出现一种调试的页面。
最简单的还是<s:debug/>。别忘了在struts的配置文件中开启调试模式
<constant name="struts.devMode" value="true" />开发时最好开了下面这行,这样配置文件改了也不用一边一边的重启服务器。
<constant name="struts.configuration.xml.reload" value="true" />
2、自定义拦截器时,不要忘记加上默认的defaultStack,可以继承自AbstractInterceptor,这样就没有init和destory了
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts><package name="auth" extends="struts-default"><interceptors><interceptor name="timeIntercepter" class="interceptors.ExecuteTimeInterceptor"></interceptor></interceptors><action name="login" class="com.neusoft.erp.action.LoginAction"method="login"><interceptor-ref name="defaultStack"></interceptor-ref><interceptor-ref name="timeIntercepter"></interceptor-ref><result name="success">/customer/main.jsp</result><result name="error">/login.jsp</result></action><action name="logout" class="com.neusoft.erp.action.LogoutAction"method="logout"><result name="success">/customer/main.jsp</result></action></package></struts>
3、action中需要session,requesht,application时,实现SessionAware等对应的接口,不要使用servletActionContext之类的与servlet耦合的方式
4、jsp中最好不用jsp的EL ${},这个符号一般用在struts配置文件中(result中get传值之类的),例如,下面的username和password就不好
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%><%@ taglib prefix="s" uri="/struts-tags"%><%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>客户管理</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"></head><body>客户管理:<span>${user.username}</span>-<span>${user.password }</span>-<span>在线人数:<s:property value="#application['login_numbers']" /></span><br><a href="<%=basePath%>customer/main.action?fun=add">增加</a><a href="<%=basePath%>customer/main.action?fun=modify">修改</a><a href="<%=basePath%>customer/main.action?fun=delete">删除</a><a href="<%=basePath%>login.jsp">登陆</a><a href="<%=basePath%>logout.action">注销</a><div><s:iterator value="#application['users']"><span><s:property value="username" /> </span><br /></s:iterator></div><s:debug></s:debug></body></html>
OGNL中,在值栈里面的数据不需要#,其他域的数据(session,request,paramator,application,attr)中需要,而且,如果给某个属性传值的时候传的是一个OGNL,如果这个属性本来就是string,需要加%,如下面第一行,value的值会是字面的‘#obj['attr']’,而不是取出里面代表的具体值
<s:url value="#obj['attr']"/><s:url value="%{#obj['attr']}"/>
- Struts2学习记录
- struts2 学习记录
- Struts2学习记录
- struts2学习记录
- Struts2学习记录1
- 学习Struts2的记录
- Struts2学习记录
- Struts2学习记录(1)
- Struts2 学习记录(2)
- Struts2 学习记录(3)
- Struts2 学习记录(4)
- Struts2 学习记录-第一天
- Struts2框架学习记录1
- struts2的dojo插件一些学习记录
- struts2 标签学习记录(一)
- 【ssh2学习记录】1、struts2框架入门
- Struts2学习记录(Struts2各项配置文件解析)
- struts2视频学习错误记录1-7讲
- Android使用HttpURLConnection显示网络图片
- java中使用队列:java.util.Queue
- 深入研究mysql中group by与order by取分类最新时间内容——同理在android里也可用
- 关于安装Discuz论坛时出现问题的解决方法
- 利用开源HTML5引擎lufylegend.js结合javascript实现的五子棋人机对弈
- struts2 学习记录
- 用Intent传递图片
- camera模组优化
- bitnami redmine安装、配置、备份、恢复
- android ndk在windows下开发环境搭建
- ASP.NET笔记--浅谈Asp.net运行机制
- Cocos2d-x学习之windows 7 android环境搭建
- acm 球和盒子模型总结
- 地球人己阻止不了程序猿们学习cocos2d-x了 (第一篇)