随笔分类 - JavaStruts
摘要:转: http://wanglihu.iteye.com/blog/1897718 1.java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor缺少asm-3.3.jar2.java.lang.NoClassDefFoundErro
阅读全文
摘要:默认情况下,Struts2的配置文件名称为struts.xml,且该文件放在src根目录下。如下图所示:如果需要修改struts.xml的位置,例如把struts.xml放到struts2文件夹下,结构如下图所示,该怎么办呢?Struts2在web.xml中的一般配置如下:struts2org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterstruts2/*为了弄清Stuts2是如何加载配置文件的,先查看Struts2的StrutsPrepareAndExecuteFilter类:packageorg.apac
阅读全文
摘要:自定义拦截器:自定义拦截器可以处理 敏感词汇等。AOP的一个体现。实现Interceptor接口,重写intercept方法,invocation.invoke()会循环调用。View Code import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.Interceptor;public class MyInterceptor implements Interceptor { public void destroy() { // TODO Auto-...
阅读全文
摘要:struts.xml<constant name="struts.custom.i18n.resources" value="app"></constant>资源文件的名称为 app_*_*.propertiesapp_en_US.propertiesView Code login.username=username:login.password=password:login.login=loginwelcome.msg=welcome:{0}app_zh_CN.propertiesView Code login.username
阅读全文
摘要:创建配置文件:格式 文件名_语言_国家.properties (文件名后面都是固定的),如:app_en_US.propertiesapp_zh_CN.propertiesJAVA调用文件:View Code public static void main(String[] args) { ResourceBundle res = ResourceBundle.getBundle("app", Locale.CHINA); System.out.println(res.getString("welcome.msg" )); }会自动调用 app_zh_C
阅读全文
摘要:所有异常不在action中处理,全部抛出。然后在struts.xml中进行处理。struts.xmlView Code <action name="*-*" class="com.bjsxt.bbs2009.action.{1}Action" method="{2}"> <result>/admin/{1}-{2}.jsp</result> <result name="input">/admin/{1}-{2}.jsp</result> <excep
阅读全文
摘要:一.property标签View Code <!-- 输出username元素 --> <li>property: <s:property value="username"/> </li> <!-- 输出字符串'username' --> <li>property 取值为字符串: <s:property value="'username'"/> </li> <!-- 找不到admin就赋值默认值 --> <li
阅读全文
摘要:一、使用OGNL访问对象 1 读取struts2中的ValueStack中的值 struts2中引入了ValueStack的概念,在struts2中默认使用ValueStack作为OGNL的StackContext的根元素 OGNL在读取根元素的时候能够直接进行读取 假设action中有 private Cat cat; private Dog dog; 俩个对象,那么在jsp页面读取方法就是 <s:property value="cat.name"/> 读取Cat的name属性的值 <s:property value="dog.name&quo
阅读全文
摘要:在struts.xml中<result type="redirect">/user_success.jsp?t=${type}</result>View Code public class UserAction extends ActionSupport { private int type; public int getType() { return type; } public void setType(int type) { this.type = type; } @Override public String...
阅读全文
摘要:struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="user" namespace="/user" extends="struts-default"> <action name="user" class="com.bjsxt.struts2.user.action.UserAction"
阅读全文
摘要:View Code <struts> <constant name="struts.devMode" value="true" /> <package name="user" namespace="/user" extends="struts-default"> <global-results> <result name="mainpage">/main.jsp</result> </global-
阅读全文
摘要:Result类型dispatcherredirectchainredirectActionfreemarkerhttpheaderstreamvelocityxsltplaintexttilesstruts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="resultTypes" namespace="/r" extends="struts-default
阅读全文
摘要:在访问不存在的页面或action的时候,可以设置跳到首页。struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index"></default-
阅读全文
摘要:struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <include file="login.xml" /></struts>login.xmlView Code <struts> <package name="login" extends="struts-default" namespace="/login"
阅读全文
摘要:有四种方法可以得到request session application等web元素。方法一LoginAction1.javaView Code public class LoginAction1 extends ActionSupport { private Map request; private Map session; private Map application; public LoginAction1() { request = (Map)ActionContext.getContext().get("request"); ...
阅读全文
摘要:UserAction.javaView Code public class UserAction extends ActionSupport { private String name; public String add() { if(name == null || !name.equals("admin")) { this.addFieldError("name", "name is error"); this.addFieldError("name", "name is too long"
阅读全文
摘要:在struts.xml中配置字符处理。struts.xmlView Code <struts> <constant name="struts.i18n.encoding" value="GBK" /> <!-- internationalization --> </package></struts>即可转换字符编码。但是在struts2.1.6中存在BUG。需要在WEB.XML重新配置以个过滤器,换成2.0的配置。或则手动配置filter,还可以用spring的filter。View Code
阅读全文
摘要:UserAction.javaView Code import com.bjsxt.struts2.user.model.User;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;public class UserAction extends ActionSupport implements ModelDriven<User>{ private User user = new User(); public String add() { ...
阅读全文
摘要:DomaimModel域模型 就是将参数封装成 dto 对象。struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="user" extends="struts-default" namespace="/user"> <action name="user" class="com.bjsxt.stru
阅读全文
摘要:struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="user" extends="struts-default" namespace="/user"> <action name="user" class="com.bjsxt.struts2.user.action.UserAction"
阅读全文

浙公网安备 33010602011771号