Struts2
共 8 篇文章
Struts2 part 8:OGNL
ValueStack内部结构 ValueStack内部数据结构 一、获取ValueStatck的两种方式 1、通过SerlvetActionContext获得 ValueStack valueStack = (ValueStack) ServletActionContext.getRequest().getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY); SerlvetActionContext中有个常量 public static final String STRUTS_VALUESTACK_KEY = "struts.value…
2015-09-06 15:58 · Struts2
Struts2 part 7:文件上传
1、单文件上传 页面表单MIME封装类型为enctype="multipart/form-data" ,提交方式为post,Struts2使用FileUpload实现文件上传 jsp <form action="${pageContext.request.contextPath}/demo01/upload1.action" method="post" enctype="multipart/form-data"> <input type="file" name="upload"><br/> <input type="submit"> </form> action,Action中必须定义三个变…
2015-09-05 15:46 · Struts2
Struts2 part6:数据校验
1、代码校验 jsp <%@ taglib uri="/struts-tags" prefix="s" %> <s:fielderror></s:fielderror> <form action="${pageContext.request.contextPath }/demo06/validata1"> 用户名<input type="text" name="username"/><br/> 密码<input type="password" name="password"/><br/> <input type="submit" name="提交"/> </form> Action,多有提交…
2015-09-04 16:43 · Struts2
Struts2 part 5:类型转换器
1、实现TypeConverter接口,实现 convertValue(java.util.Map<java.lang.String,java.lang.Object> context, java.lang.Object target, java.lang.reflect.Member member, java.lang.String propertyName, java.lang.Object value, java.lang.Class toType) 2、继承DefaultTypeConverter类,覆写 convertValue(java.util.Map<java.lang.St…
2015-09-04 11:03 · Struts2
Struts2 part 4:Action封装请求参数
Action接受页面的请求参数,有两种类型模型驱动、属性驱动,可以分为三种方式 1、Action自身作为model对象,使用setter封装页面参数(属性驱动) jsp <form action="${pageContext.request.contextPath }/demo05/param1.action" method="post"> 文本<input type="text" name="username" /><br/> 多选 <input type="checkbox" name="programmes" value="C" />C <input type="checkbox" n…
2015-09-02 20:19 · Struts2
Struts2 part 3:在Action中使用ServletAPI
1、使用ActionContext对象,采用解耦合的方式访问ServletAPI ActionContext context = ActionContext.getContext(); jsp <form action="${pageContext.request.contextPath }/demo04/scope1.action" method="post"> <input type="text" name="scopetext" /> <input type="submit" value="提交" /> </form> action,通过context获取的对象都是Map,这种方式完全…
2015-09-02 16:31 · Struts2
Struts2 part 2:Action的编写方式
Action的编写方式: 1、POJO对象 public class RequestAction { public String execute() { return "success"; } } 2、实现Action接口 public class RequestAction2 implements Action { @Override public String execute() throws Exception { return SUCCESS; } } 接口中定义了5种逻辑视图名称 public static final String SUCCESS = "success"; // …
2015-09-02 15:41 · Struts2
Struts2 part 1:快速入门
导入jar包,struts-2.3.4\apps\struts2-blank.war 中所有jar包 struts2-core-2.3.1.1.jar:Struts 2框架的核心类库 xwork-core-2.3.1.1.jar:Command模式框架,WebWork和Struts2都基于xwork ognl-3.0.3.jar:对象图导航语言(Object Graph Navigation Language), struts2框架通过其读写对象的属性 freemarker-2.3.18.jar:Struts 2的UI标签的模板使用FreeMarker编写 commons-logging-1…
2015-09-02 10:48 · Struts2