- 浏览: 893450 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (687)
- java (127)
- servlet (38)
- struts (16)
- spring (22)
- hibernate (40)
- javascript (58)
- jquery (18)
- tomcat (51)
- 设计模式 (6)
- EJB (13)
- jsp (3)
- oracle (29)
- RUP (2)
- ajax (3)
- java内存管理 (4)
- java线程 (12)
- socket (13)
- path (5)
- XML (10)
- swing (2)
- UML (1)
- JBPM (2)
- 开发笔记 (45)
- Note参考 (15)
- JAXB (4)
- Quartz (2)
- 乱码 (2)
- CSS (2)
- Exception (4)
- Tools (7)
- sqlserver (3)
- DWR (7)
- Struts2 (47)
- WebService (2)
- 问题解决收藏 (7)
- JBOSS (7)
- cache (10)
- easyUI (19)
- jQuery Plugin (11)
- FreeMarker (6)
- Eclipse (2)
- Compass (2)
- JPA (1)
- WebLogic (1)
- powerdesigner (1)
- mybatis (1)
最新评论
-
bugyun:
受教了,谢谢
java 正则表达式 过滤html标签 -
xiongxingxing_123:
学习了,感谢了
java 正则表达式 过滤html标签 -
wanmeinange:
那如果无状态的。对同一个任务并发控制怎么做?比如继承Quart ...
quartz中参数misfireThreshold的详解 -
fanjieshanghai:
...
XPath 元素及属性查找 -
tianhandigeng:
还是没明白
quartz中参数misfireThreshold的详解
专栏地址:http://www.iteye.com/wiki/struts2/1462-result-in-struts2
Struts2将Result列为一个独立的层次,可以说是整个Struts2的Action层架构设计中的另外一个精华所在。Result之所以成为一个层次,其实是为了解决MVC框架中,如何从Control层转向View层这样一个问题而存在的。所以,接下来我们详细讨论一下Result的方方面面。
Result的职责
Result作为一个独立的层次存在,必然有其存在的价值,它也必须完成它所在的层次的职责。Result是为了解决如何从Control层转向View层这样一个问题而存在的,那么Result最大的职责,就是架起Action到View的桥梁。具体来说,我把这些职责大概分成以下几个方面:
封装跳转逻辑
Result的首要职责,是封装Action层到View层的跳转逻辑。之前我们已经反复提到,Struts2的Action是一个与Web容器无关的POJO。所以,在Action执行完毕之后,框架需要把代码的执行权重新交还给Web容器,并转向到相应的页面或者其他类型的View层。
而这个跳转逻辑,就由Result来完成。这样,好处也是显而易见的,对Action屏蔽任何Web容器的相关信息,使得每个层次更加清晰。
View层的显示类型非常多,有最常见的JSP、当下非常流行的Freemarker/Velocity模板、Redirect到一个新的地址、文本流、图片流、甚至是JSON对象等等。所以Result层的独立存在,就能够对这些显示类型进行区分,并封装合理的跳转逻辑。
以JSP转向为例,在Struts2自带的ServletDispatcherResult中就存在着核心的JSP跳转逻辑:
- HttpServletRequest request = ServletActionContext.getRequest();
- RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation);
- ....
- dispatcher.forward(request, response);
HttpServletRequest request = ServletActionContext.getRequest(); RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation); .... dispatcher.forward(request, response);
再以Redirect重定向为例,在Struts2自带的ServletRedirectResult中,也同样存在着重定向的核心代码:
- HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
- ....
- response.sendRedirect(finalLocation);
HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE); .... response.sendRedirect(finalLocation);
由此可见,绝大多数的Result,都封装了与Web容器相关的跳转逻辑,由于这些逻辑往往需要和Servlet对象打交道,所以,遵循Struts2的基本原则,将它作为一个独立的层次,从而将Action从Web容器中解放出来。
准备显示数据
之前提到,View层的展现方式很多,除了传统的JSP以外,还有类似Freemarker/Velocity这样的模板。根据模板显示的基本原理,需要将预先定义好的模板(Template)和需要展示的数据(Model)组织起来,交给模板引擎,才能够正确显示。而这部分工作,就由Result层来完成。
以Struts2自带的FreemarkerResult为例,在Result中,就存在着为模板准备数据的逻辑代码:
- protected TemplateModel createModel() throws TemplateModelException {
- ServletContext servletContext = ServletActionContext.getServletContext();
- HttpServletRequest request = ServletActionContext.getRequest();
- HttpServletResponse response = ServletActionContext.getResponse();
- ValueStack stack = ServletActionContext.getContext().getValueStack();
- Object action = null;
- if(invocation!= null ) action = invocation.getAction(); //Added for NullPointException
- return freemarkerManager.buildTemplateModel(stack, action, servletContext, request, response, wrapper);
- }
protected TemplateModel createModel() throws TemplateModelException { ServletContext servletContext = ServletActionContext.getServletContext(); HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); ValueStack stack = ServletActionContext.getContext().getValueStack(); Object action = null; if(invocation!= null ) action = invocation.getAction(); //Added for NullPointException return freemarkerManager.buildTemplateModel(stack, action, servletContext, request, response, wrapper); }
有兴趣的读者可以顺着思路去看源码,看看这些Result到底是如何获取各种对象的值的。
控制输出行为
有的时候,针对同一种类型的View展示,我们可能会有不同的输出行为。具体来说,可能有时候,我们需要对输出流指定特定的BufferSize、Encoding等等。Result层,作为一个独立的层次,可以提供极大的扩展性,从而保证我们能够定义自己期望的输出类型。
以Struts2自带的HttpHeaderResult为例:
- public void execute(ActionInvocation invocation) throws Exception {
- HttpServletResponse response = ServletActionContext.getResponse();
- if (status != -1) {
- response.setStatus(status);
- }
- if (headers != null) {
- ValueStack stack = ActionContext.getContext().getValueStack();
- for (Iterator iterator = headers.entrySet().iterator();
- iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- String value = (String) entry.getValue();
- String finalValue = parse ? TextParseUtil.translateVariables(value, stack) : value;
- response.addHeader((String) entry.getKey(), finalValue);
- }
- }
- }
public void execute(ActionInvocation invocation) throws Exception { HttpServletResponse response = ServletActionContext.getResponse(); if (status != -1) { response.setStatus(status); } if (headers != null) { ValueStack stack = ActionContext.getContext().getValueStack(); for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String value = (String) entry.getValue(); String finalValue = parse ? TextParseUtil.translateVariables(value, stack) : value; response.addHeader((String) entry.getKey(), finalValue); } } }
我们可以在这里添加我们自定义的内容到HttpHeader中去,从而控制Http的输出。
Result的定义
让我们来看看Result的接口定义:
- public interface Result extends Serializable {
- /**
- * Represents a generic interface for all action execution results, whether that be displaying a webpage, generating
- * an email, sending a JMS message, etc.
- */
- public void execute(ActionInvocation invocation) throws Exception;
- }
public interface Result extends Serializable { /** * Represents a generic interface for all action execution results, whether that be displaying a webpage, generating * an email, sending a JMS message, etc. */ public void execute(ActionInvocation invocation) throws Exception; }
这个接口定义非常简单,通过传入ActionInvocation,执行一段逻辑。我们来看看Struts2针对这个接口实现的一个抽象类,它规定了许多默认实现:
- public abstract class StrutsResultSupport implements Result, StrutsStatics {
- private static final Log _log = LogFactory.getLog(StrutsResultSupport.class);
- /** The default parameter */
- public static final String DEFAULT_PARAM = "location";
- private boolean parse;
- private boolean encode;
- private String location;
- private String lastFinalLocation;
- public StrutsResultSupport() {
- this(null, true, false);
- }
- public StrutsResultSupport(String location) {
- this(location, true, false);
- }
- public StrutsResultSupport(String location, boolean parse, boolean encode) {
- this.location = location;
- this.parse = parse;
- this.encode = encode;
- }
- // setter method 省略
- /**
- * Implementation of the <tt>execute</tt> method from the <tt>Result</tt> interface. This will call
- * the abstract method {@link #doExecute(String, ActionInvocation)} after optionally evaluating the
- * location as an OGNL evaluation.
- *
- * @param invocation the execution state of the action.
- * @throws Exception if an error occurs while executing the result.
- */
- public void execute(ActionInvocation invocation) throws Exception {
- lastFinalLocation = conditionalParse(location, invocation);
- doExecute(lastFinalLocation, invocation);
- }
- /**
- * Parses the parameter for OGNL expressions against the valuestack
- *
- * @param param The parameter value
- * @param invocation The action invocation instance
- * @return The resulting string
- */
- protected String conditionalParse(String param, ActionInvocation invocation) {
- if (parse && param != null && invocation != null) {
- return TextParseUtil.translateVariables(param, invocation.getStack(),
- new TextParseUtil.ParsedValueEvaluator() {
- public Object evaluate(Object parsedValue) {
- if (encode) {
- if (parsedValue != null) {
- try {
- // use UTF-8 as this is the recommended encoding by W3C to
- // avoid incompatibilities.
- return URLEncoder.encode(parsedValue.toString(), "UTF-8");
- }
- catch(UnsupportedEncodingException e) {
- _log.warn("error while trying to encode ["+parsedValue+"]", e);
- }
- }
- }
- return parsedValue;
- }
- });
- } else {
- return param;
- }
- }
- /**
- * Executes the result given a final location (jsp page, action, etc) and the action invocation
- * (the state in which the action was executed). Subclasses must implement this class to handle
- * custom logic for result handling.
- *
- * @param finalLocation the location (jsp page, action, etc) to go to.
- * @param invocation the execution state of the action.
- * @throws Exception if an error occurs while executing the result.
- */
- protected abstract void doExecute(String finalLocation, ActionInvocation invocation) throws Exception;
- }
public abstract class StrutsResultSupport implements Result, StrutsStatics { private static final Log _log = LogFactory.getLog(StrutsResultSupport.class); /** The default parameter */ public static final String DEFAULT_PARAM = "location"; private boolean parse; private boolean encode; private String location; private String lastFinalLocation; public StrutsResultSupport() { this(null, true, false); } public StrutsResultSupport(String location) { this(location, true, false); } public StrutsResultSupport(String location, boolean parse, boolean encode) { this.location = location; this.parse = parse; this.encode = encode; } // setter method 省略 /** * Implementation of the <tt>execute</tt> method from the <tt>Result</tt> interface. This will call * the abstract method {@link #doExecute(String, ActionInvocation)} after optionally evaluating the * location as an OGNL evaluation. * * @param invocation the execution state of the action. * @throws Exception if an error occurs while executing the result. */ public void execute(ActionInvocation invocation) throws Exception { lastFinalLocation = conditionalParse(location, invocation); doExecute(lastFinalLocation, invocation); } /** * Parses the parameter for OGNL expressions against the valuestack * * @param param The parameter value * @param invocation The action invocation instance * @return The resulting string */ protected String conditionalParse(String param, ActionInvocation invocation) { if (parse && param != null && invocation != null) { return TextParseUtil.translateVariables(param, invocation.getStack(), new TextParseUtil.ParsedValueEvaluator() { public Object evaluate(Object parsedValue) { if (encode) { if (parsedValue != null) { try { // use UTF-8 as this is the recommended encoding by W3C to // avoid incompatibilities. return URLEncoder.encode(parsedValue.toString(), "UTF-8"); } catch(UnsupportedEncodingException e) { _log.warn("error while trying to encode ["+parsedValue+"]", e); } } } return parsedValue; } }); } else { return param; } } /** * Executes the result given a final location (jsp page, action, etc) and the action invocation * (the state in which the action was executed). Subclasses must implement this class to handle * custom logic for result handling. * * @param finalLocation the location (jsp page, action, etc) to go to. * @param invocation the execution state of the action. * @throws Exception if an error occurs while executing the result. */ protected abstract void doExecute(String finalLocation, ActionInvocation invocation) throws Exception; }
很显然,这个默认实现是为那些类似JSP,Freemarker或者Redirect这样的页面跳转的Result而准备的一个基类,它规定了Result将要跳转到的具体页面的位置、是否需要解析参数,等等。
如果我们试图编写自定义的Result,我们可以实现Result接口,并在struts.xml中进行声明:
- public class CustomerResult implements Result {
- public void execute(ActionInvocation invocation) throws Exception {
- // write your code here
- }
- }
public class CustomerResult implements Result { public void execute(ActionInvocation invocation) throws Exception { // write your code here } }
<result-type name="customerResult" class="com.javaeye.struts2.CustomerResult"/>
常用的Result
接下来,大致介绍一下Struts2内部已经实现的Result,并看看他们是如何工作的。
dispatcher
- <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
dispatcher主要用于返回JSP,HTML等以页面为基础View视图,这个也是Struts2默认的Result类型。
在使用dispatcher时,唯一需要指定的,是JSP或者HTML页面的位置,这个位置将被用于定位返回的页面:
<result name="success">/index.jsp</result>
而Struts2本身也没有对dispatcher做出什么特殊的处理,只是简单的使用Servlet API进行forward。
freemarker / velocity
- <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
- <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/> <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
随着模板技术的越来越流行,使用Freemarker或者Velocity模板进行View层展示的开发者越来越多。Struts2同样为模板作为Result做出了支持。由于模板的显示需要模板(Template)与数据(Model)的紧密配合,所以在Struts2中,这两个Result的主要工作是为模板准备数据。
以Freemarker为例,我们来看看它是如何为模板准备数据的:
- public void doExecute(String location, ActionInvocation invocation) throws IOException, TemplateException {
- this.location = location;
- this.invocation = invocation;
- this.configuration = getConfiguration();
- this.wrapper = getObjectWrapper();
- // 获取模板的位置
- if (!location.startsWith("/")) {
- ActionContext ctx = invocation.getInvocationContext();
- HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
- String base = ResourceUtil.getResourceBase(req);
- location = base + "/" + location;
- }
- // 得到模板
- Template template = configuration.getTemplate(location, deduceLocale());
- // 为模板准备数据
- TemplateModel model = createModel();
- // 根据模板和数据进行输出
- // Give subclasses a chance to hook into preprocessing
- if (preTemplateProcess(template, model)) {
- try {
- // Process the template
- template.process(model, getWriter());
- } finally {
- // Give subclasses a chance to hook into postprocessing
- postTemplateProcess(template, model);
- }
- }
- }
public void doExecute(String location, ActionInvocation invocation) throws IOException, TemplateException { this.location = location; this.invocation = invocation; this.configuration = getConfiguration(); this.wrapper = getObjectWrapper(); // 获取模板的位置 if (!location.startsWith("/")) { ActionContext ctx = invocation.getInvocationContext(); HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST); String base = ResourceUtil.getResourceBase(req); location = base + "/" + location; } // 得到模板 Template template = configuration.getTemplate(location, deduceLocale()); // 为模板准备数据 TemplateModel model = createModel(); // 根据模板和数据进行输出 // Give subclasses a chance to hook into preprocessing if (preTemplateProcess(template, model)) { try { // Process the template template.process(model, getWriter()); } finally { // Give subclasses a chance to hook into postprocessing postTemplateProcess(template, model); } } }
从源码中,我们可以看到,createModel()方法真正为模板准备需要显示的数据。而之前,我们已经看到过这个方法的源码,这个方法所准备的数据不仅包含ValueStack中的数据,还包含了被封装过的HttpServletRequest,HttpSession等对象的数据。从而使得模板能够以它特定的语法输出这些数据。
Velocity的Result也是类似,有兴趣的读者可以顺着思路继续深究源码。
redirect
- <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
- <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
- <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/> <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/> <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
如果你在Action执行完毕后,希望执行另一个Action,有2种方式可供选择。一种是forward,另外一种是redirect。有关forward和redirect的区别,这里我就不再展开,这应该属于Java程序员的基本知识。在Struts2中,分别对应这两种方式的Result,就是chain和redirect。
先来谈谈redirect,既然是重定向,那么源地址与目标地址之间是2个不同的HttpServletRequest。所以目标地址将无法通过ValueStack等Struts2的特性来获取源Action中的数据。如果你需要对目标地址传递参数,那么需要在目标地址url或者配置文件中指出:
- <!--
- The redirect-action url generated will be :
- /genReport/generateReport.jsp?reportType=pie&width=100&height=100
- -->
- <action name="gatherReportInfo" class="...">
- <result name="showReportResult" type="redirect">
- <param name="location">generateReport.jsp</param>
- <param name="namespace">/genReport</param>
- <param name="reportType">pie</param>
- <param name="width">${width}</param>
- <param name="height">${height}</param>
- </result>
- </action>
<!-- The redirect-action url generated will be : /genReport/generateReport.jsp?reportType=pie&width=100&height=100 --> <action name="gatherReportInfo" class="..."> <result name="showReportResult" type="redirect"> <param name="location">generateReport.jsp</param> <param name="namespace">/genReport</param> <param name="reportType">pie</param> <param name="width">${width}</param> <param name="height">${height}</param> </result> </action>
同时,Redirect的Result支持在配置文件中,读取并解析源Action中ValueStack的值,并成为参数传递到Redirect的地址中。上面给出的例子中,width和height就是ValueStack中的值。
chain
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
再来谈谈chain,之前提到,chain其实只是在一个action执行完毕之后,forward到另外一个action,所以他们之间是共享HttpServletRequest的。在使用chain作为Result时,往往会配合使用ChainingInterceptor。有关ChainingInterceptor,Struts2的Reference说明了其作用:
也就是说,ChainingInterceptor的作用是在Action直接传递数据。事实上,源Action中ValueStack的数据会被做一次Copy,这样,2个Action中的数据都在ValueStack中,使得对于前台来说,通过ValueStack来取数据,是透明而共享的。
chain这个Result有一些常用的使用情景,这点在Struts2的Reference中也有说明:
One common use of Action chaining is to provide lookup lists (like for a dropdown list of states). Since these Actions get put on the ValueStack, their properties will be available in the view. This functionality can also be done using the ActionTag to execute an Action from the display page.
比如说,一张页面中,你可能有许多数据要显示,而某些数据的获取方式可能被很多不同的页面共享(典型来说,“推荐文章”这个小栏目的数据获取,可能会被很多页面所共享)。这种情况下,可以把这部分逻辑抽取到一个独立Action中,并使用chain,将这个Action与主Action串联起来。这样,最后到达页面的时候,页面始终可以得到每个Action中的数据。
不过chain这种Result,是在使用时需要慎重考虑的一种Result:
而Struts2也做出了理由上的说明:
Ideally, Action classes should be as short as possible. All the core logic should be pushed back to a support class or a business facade, so that Actions only call methods. Actions are best used as adapters, rather than as a class where coding logic is defined.
从实战上将,使用chain作为Result也的确存在着上面所说的许多问题,我个人也是非常不推崇滥用这种Result。尤其是,对于使用Spring和Hibernate的朋友来说,如果你开启OpenSessionInView模式,那么Hibernate的session是跟随HttpServletRequest的,所以session在整个action链中共享。这会为我们的编程带来极大的麻烦。因为我们知道Hibernate的session会保留一份一级缓存,在action链中,共享一级缓存无疑会为你的调试工作带来很大的不方便。
所以,谨慎使用chain作为你的Result,应该成为一条最佳实践。
stream
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
StreamResult等价于在Servlet中直接输出Stream流。这种Result被经常使用于输出图片、文档等二进制流到客户端。通过使用StreamResult,我们只需要在Action中准备好需要输出的InputStream即可。
- <result name="success" type="stream">
- <param name="contentType">image/jpeg</param>
- <param name="inputName">imageStream</param>
- <param name="contentDisposition">filename="document.pdf"</param>
- <param name="bufferSize">1024</param>
- </result> </o
发表评论
-
ognl表达式
2011-07-07 00:36 1301OGNL是Object Graphic Navigation ... -
在Struts 2_0中实现表单数据校验
2011-07-07 00:02 1147转换与校验(Conversion & Validati ... -
简单的struts2输入校验框架
2011-05-13 23:43 10901.输入页面login.jsp: <%@ page ... -
struts2在学习(十二)--表单验证的两种方式
2011-05-13 23:13 960第四个示例:注解方式校验器---用户注册页面user2_reg ... -
struts2在学习(十一)--表单验证的两种方式
2011-05-13 23:09 909第二个示例:XML配置式校验器---登录和注册页面user_l ... -
struts2在学习(十)--表单验证的两种方式
2011-05-13 22:56 11661. Struts2中的输入校验2. 编码方式校验 1) A ... -
struts2采用convention-plugin实现零配置
2011-05-13 21:58 1120最近开始关注struts2的新特性,从这个版本开始,Strut ... -
基于SSH2框架Struts2拦截器的登录验证实现
2011-04-01 22:00 2293通过之前的Struts2.1.6+Spring2.5.6+H ... -
通过ActionContext类访问Servlet对象
2011-04-01 21:40 1924ActionContext类位于com.opensympho ... -
webwork 之销毁session
2011-04-01 17:35 1773销毁的意思?不是清空 ... -
Struts2 Convention Plugin(三)
2011-03-18 01:26 1206Annotation 参考Convention使用某些注解语句 ... -
Struts2 Convention Plugin(二)
2011-03-18 01:25 1155Results and result codesStruts ... -
Struts2 Convention Plugin(一)
2011-03-18 01:25 1105Introduction从struts2.1版本开始,Conv ... -
struts2页面中的标签调用类的方法
2011-03-15 16:33 1624<s:set name="str" ... -
Apache Struts 2.2.1 GA版发布
2011-03-14 17:14 1339昨日,Apache软件基金会发布了Struts 2.2.1 G ... -
spring2 +hibernate 3 + struts 配置
2011-03-14 15:15 12191. web.xml 1. <?xml versi ... -
Struts2 中action之间的跳转
2011-03-14 12:32 1258转载于http://zhou568xiao.iteye.com ... -
Struts2 的Result Type
2011-03-13 16:35 1050http://www.blogjava.net/duanzhi ... -
struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
2011-03-13 16:32 1627dispatcher 为默认跳转类型,用于返回一个视图资源(如 ... -
struts2防止重复提交
2011-03-10 23:07 1296struts2的防止重复提交 也使用到了 token (令牌机 ...
相关推荐
Struts2提供了丰富的自定义标签库,简化了视图层的开发。例如,`<s:form>`、`<s:textfield>`等标签用于创建表单元素,`<s:property>`用于显示Model中的数据。 **7. 国际化与本地化** Struts2支持国际化,开发者可以...
Struts2是一个基于MVC(Model-View-Controller)设计模式的Java web应用程序框架,它在Struts1的基础上进行了很多改进和增强,提供了更强大的功能和更好的性能。本教程将深入探讨Struts2的核心概念、架构以及实际...
这篇博客“Struts2 ——2、各种Action写法和配置”着重讲解了在Struts2框架中如何创建和配置不同的Action,以便更好地理解和运用这个框架。 在Struts2中,Action是处理用户请求的核心组件,它负责业务逻辑的处理,...
通过这些jar包,Struts2为开发者提供了丰富的功能,包括但不限于:Action的生命周期管理、结果映射、拦截器链、类型转换、国际化支持、插件机制、以及强大的视图渲染。同时,Struts2的灵活性使其可以与其他框架(如...
要深入学习和掌握Struts2,建议阅读官方文档,参与实际项目实践,也可以参考相关的技术书籍和教程,例如《Struts2技术内幕——深入解析Struts2架构设计与实现原理》等资源,来提升对Struts2框架的全面理解。
本书《Struts2技术内幕——深入解析Struts2架构设计与实现原理》结合提供的《struts2基础.chm》资料,为我们提供了深入理解Struts2内部机制的机会。 首先,Struts2的核心在于它的拦截器(Interceptor)机制。拦截器...
核心技术篇首先分析了Struts2中多种具有代表性的设计模式,然后对Struts2中的精华——OGNL表达式引擎和XWork框架的原理及机制进行了全面深入的分析和讲解。运行主线篇首先对Struts2的两大运行主线——初始化主线和...
Struts教程——丰伟 1. **概述** 在本文中,我们将深入理解Struts Framework,这是一种基于MVC(Model-View-Controller)设计模式的Java Web应用开发框架。Struts为开发者提供了一种结构化的解决方案,使得创建...
通过学习和熟练掌握Struts2的Result配置,开发者能够更好地控制Action与视图之间的交互,从而构建出高效、健壮的Java Web应用程序。通过实践和阅读博文(如https://huangminwen.iteye.com/blog/996219),你可以深入...
Struts2 Result类型是Struts2框架中一个关键的概念,它是动作执行完成后跳转到下一个页面或处理逻辑的核心机制。Result类型定义了如何处理动作执行的结果,使得开发者能够灵活地控制应用程序的流程。 首先,我们...
【标题】"myeclipse+struts实例——2"是一个基于Java EE(J2EE)技术栈的项目实例,主要涉及MyEclipse集成开发环境、Struts框架和Tomcat服务器的使用。在这个实例中,开发者将学习如何在MyEclipse中创建一个简单的...
"Struts2 技术内幕——深入解析Struts2架构设计"这本书深入探讨了Struts2的核心机制和设计理念,帮助开发者更好地理解和应用这个框架。 Struts2的核心组件包括Action、Interceptor、Result和Configuration。Action...
总的来说,Struts2的Result Type是控制应用程序流程的关键机制,它使得在不同场景下灵活地处理Action结果变得可能。理解并熟练运用各种Result Type,能够帮助开发者更高效地构建和维护Struts2应用。通过阅读和学习...
这本书《Struts2技术内幕——深入解析Struts2架构设计与实现原理》深入探讨了Struts2的核心机制和设计理念,旨在帮助开发者更好地理解和运用这个框架。 首先,Struts2的出现是为了解决Struts1在MVC模式中的局限性,...
Struts2并不是Struts1.x的直接升级,而是结合了WebWork框架的核心机制,因此它具有更稳定、高性能和成熟的设计。 Struts2的工作机制主要包括以下几个关键部分: 1. **过滤器Dispatcher**: Struts2的核心是`...
【标题】"myeclipse+struts实例——3"是一个基于Java EE(j2ee)开发的项目,它利用MyEclipse作为集成开发环境,Struts作为MVC框架,以及Tomcat作为应用服务器来实现文件上传功能。在这个实例中,重点在于如何在Web...
使用Struts做登录验证的步骤: 1 搭建环境: A 导包 B 建配置文件 struts-config.xml C 修改web.xml 2 建一个 ActionForm 3 建一个 Action 4 页面上面的事情
《SSM框架整合详解——基于spring-mybatis-struts2-master的实战分析》 在Java Web开发领域,SSM(Spring、Struts2、MyBatis)框架的组合被广泛使用,因其灵活性和强大的功能而备受青睐。本篇文章将深入探讨这个...