struts2--结果集转发类型
<result name="success" type="转发类型">/xxx.jsp</result>
在"struts2-core-2.5.5.jar"==>"struts-default.xml"下的系统默认配置
<result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.result.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.result.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.result.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.result.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.result.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.result.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.result.PlainTextResult" />
<result-type name="postback" class="org.apache.struts2.result.PostbackResult" />
</result-types>
chain 转发到一个action,而不是页面
这个结果调用其他action,完成它自己定义的拦截器堆栈和结果。只能请求action,如果请求视图资源会报错。
需要注意的就是与redirect的区别,请求转发是还在当前请求,而redirect会响应一次浏览器然后浏览器再根据响应请求重定向的资源,
dispatcher (默认类型,如果没有配置类型默认就是dispatcher,转发到一个页面)
当一个请求到来,服务器直接转发到另一个页面,不能是另一个action。由于这个过程在服务器内部完成,客户端(浏览器)并不知道,
所以在地址栏不会显示真实访问的页面,而显示都是所请求的action的地址。在servlet中相当与forword转发。
包括或转发到一个视图(通常是一个jsp)。在后台Struts2将使用一个RequestDispatcher,目标servlet/JSP接收相同的request/response对象作为原始的servlet或JSP。
因此,可以使用request.setAttribute()传递数据- - - Struts的action是可用的。如果请求action会找不到资源。
redirectAction
重定向至Action,完成与它自己的拦截器堆栈和结果。
相对于redirect来说,redirectAction只能请求action,如果请求视图资源会报错,
然后还有个小区别就是redirectAction会为url添加.action后缀而redirect不会,但是两者都可以通过url传参
redirect 重定向到一个页面或另一个action或一个网址
当一个请求到来,服务端将实际地址response给浏览器,然后浏览器重新发起请求,这个过程,浏览器是知道访问的页面的实际地址的,
所以在浏览器的地址栏显示的是实际访问的jsp页面地址。但是这种类型不能重定向到一个action.
让客户端请求另外的网络资源,可以为action,也可以为视图资源。
文档上是这么解释的:
调用{ @link HttpServletResponse # sendRedirect(String)sendRedirect }方法到指定的地址。 响应是告诉重定向浏览器到指定的地址(一个新的请求从客户端)。
这样做的结果意味着action(action instance, action errors, field errors等)只是执行失败,不再可用。
这是因为action是一个单线程模式(single-thread model)。唯一的传参方法是通过会话或用OGNL表达式,url参数(url ?名称=值)
httpheader
可以通过设置HTTP headers和status的值来发送错误信息给客户端。
他的参数有这些:
status - the http servlet response status code that should be set on a response.
parse - true by default. If set to false, the headers param will not be parsed for Ognl expressions.
headers - header values.
error - the http servlet response error code that should be set on a response.
errorMessage - error message to be set on response if 'error' is set.
stream :这个返回类型主要用作下载文件或者在浏览器上显示PDF等文档
plainText :响应以plain形式返回给客户端,相当于response.setContentType("text/plain; charset="+charSet);
velocity :使用Servlet容器的JspFactory,这个结果模拟一个JSP执行环境,然后显示一个Velocity模板,将直接传输到Servlet输出。
freemarker :呈现一个视图使用Freemarker模板引擎。。
xslt :调用一个xslt文件并解析执行。
Tiles是一个模板框架被设计来轻松地允许创建web应用程序的页面具有一致的外观和感觉。它可以用于页面和组件化装饰。
特性:支持在Freemarker,JSP,Velocity使用Tiles
<result name="success" type="转发类型">/xxx.jsp</result>
在"struts2-core-2.5.5.jar"==>"struts-default.xml"下的系统默认配置
<result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.result.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.result.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.result.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.result.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.result.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.result.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.result.PlainTextResult" />
<result-type name="postback" class="org.apache.struts2.result.PostbackResult" />
</result-types>
chain 转发到一个action,而不是页面
这个结果调用其他action,完成它自己定义的拦截器堆栈和结果。只能请求action,如果请求视图资源会报错。
需要注意的就是与redirect的区别,请求转发是还在当前请求,而redirect会响应一次浏览器然后浏览器再根据响应请求重定向的资源,
dispatcher (默认类型,如果没有配置类型默认就是dispatcher,转发到一个页面)
当一个请求到来,服务器直接转发到另一个页面,不能是另一个action。由于这个过程在服务器内部完成,客户端(浏览器)并不知道,
所以在地址栏不会显示真实访问的页面,而显示都是所请求的action的地址。在servlet中相当与forword转发。
包括或转发到一个视图(通常是一个jsp)。在后台Struts2将使用一个RequestDispatcher,目标servlet/JSP接收相同的request/response对象作为原始的servlet或JSP。
因此,可以使用request.setAttribute()传递数据- - - Struts的action是可用的。如果请求action会找不到资源。
redirectAction
重定向至Action,完成与它自己的拦截器堆栈和结果。
相对于redirect来说,redirectAction只能请求action,如果请求视图资源会报错,
然后还有个小区别就是redirectAction会为url添加.action后缀而redirect不会,但是两者都可以通过url传参
redirect 重定向到一个页面或另一个action或一个网址
当一个请求到来,服务端将实际地址response给浏览器,然后浏览器重新发起请求,这个过程,浏览器是知道访问的页面的实际地址的,
所以在浏览器的地址栏显示的是实际访问的jsp页面地址。但是这种类型不能重定向到一个action.
让客户端请求另外的网络资源,可以为action,也可以为视图资源。
文档上是这么解释的:
调用{ @link HttpServletResponse # sendRedirect(String)sendRedirect }方法到指定的地址。 响应是告诉重定向浏览器到指定的地址(一个新的请求从客户端)。
这样做的结果意味着action(action instance, action errors, field errors等)只是执行失败,不再可用。
这是因为action是一个单线程模式(single-thread model)。唯一的传参方法是通过会话或用OGNL表达式,url参数(url ?名称=值)
httpheader
可以通过设置HTTP headers和status的值来发送错误信息给客户端。
他的参数有这些:
status - the http servlet response status code that should be set on a response.
parse - true by default. If set to false, the headers param will not be parsed for Ognl expressions.
headers - header values.
error - the http servlet response error code that should be set on a response.
errorMessage - error message to be set on response if 'error' is set.
stream :这个返回类型主要用作下载文件或者在浏览器上显示PDF等文档
plainText :响应以plain形式返回给客户端,相当于response.setContentType("text/plain; charset="+charSet);
velocity :使用Servlet容器的JspFactory,这个结果模拟一个JSP执行环境,然后显示一个Velocity模板,将直接传输到Servlet输出。
freemarker :呈现一个视图使用Freemarker模板引擎。。
xslt :调用一个xslt文件并解析执行。
Tiles是一个模板框架被设计来轻松地允许创建web应用程序的页面具有一致的外观和感觉。它可以用于页面和组件化装饰。
特性:支持在Freemarker,JSP,Velocity使用Tiles