可以在struts2-core-{version}.jar中找到struts-default.xml,里面列举了当前可以使用的所有result-type以及对应的class
此处是struts2.2.3的
1. <result-types>
2. <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
3. <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
4. <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
5. <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
6. <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
7. <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
8. <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
9. <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
10. <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
11. <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
12. </result-types>
1.chain
该类型是请求转发给其他的action,如果为jsp则会报错
需要注意的就是与redirect的区别,请求转发是还在当前请求,
而redirect会响应一次浏览器然后浏览器再根据响应请求重定向的资源,注意看url的变化就明白了!
下面是apache给的示例,这个比较简单,没什么说的,
<span class="code-tag"></span><div style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.53125px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div style="padding-left: 45px;"><div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[html]</strong> <a target=_blank href="javascript:void(0)#" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="javascript:void(0)#" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="javascript:void(0)#" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="javascript:void(0)#" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 483px; top: 957px; width: 29px; height: 14px; z-index: 99;"></div></div></div><ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">package</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"public"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">extends</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"struts-default"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comments" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;"><!-- Chain creatAccount to login, using the default parameter --></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">action</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"createAccount"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"..."</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">type</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"chain"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">login</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">action</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">action</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"login"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"..."</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span class="comments" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;"><!-- Chain to another namespace --></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">type</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"chain"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">param</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"actionName"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">dashboard</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">param</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">param</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"namespace"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">/secure</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">param</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">action</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">package</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">package</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"secure"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">extends</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"struts-default"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">namespace</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"/secure"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">action</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"dashboard"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"..."</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">dashboard.jsp</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">action</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">package</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li></ol></div>
<strong><span style="font-size: 16px;">2.dispatcher</span></strong>
请求转发视图资源,比如jsp,html,如果请求action会找不到资源,
请求转发的问题看1中的说明
apache给的示例。。也没啥说的
<div style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.53125px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div style="padding-left: 45px;"><div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[html]</strong> <a target=_blank href="javascript:void(0)#" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="javascript:void(0)#" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="javascript:void(0)#" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="javascript:void(0)#" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 483px; top: 1512px; width: 29px; height: 14px; z-index: 99;"></div></div></div><ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"success"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">type</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"dispatcher"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">param</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"location"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">foo.jsp</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">param</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li></ol></div>
<strong><span style="font-size: 16px;">3.httpheader</span></strong>
这个挺有意思的,可以随便更改响应状态
比如下面的这个示例
<div style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.53125px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div style="padding-left: 45px;"><div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[html]</strong> <a target=_blank href="javascript:void(0)#" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="javascript:void(0)#" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="javascript:void(0)#" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="javascript:void(0)#" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 483px; top: 1735px; width: 29px; height: 14px; z-index: 99;"></div></div></div><ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">action</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"test"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"com.iss.action.TestAction"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"success"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">type</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"httpheader"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"><</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">param</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">name</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"status"</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">400</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">param</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">result</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;"></</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">action</span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">></span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li></ol></div>
当action返回SUCCESS的时候,会将响应状态修改为400,客户端错误的请求,
还有其他的状态可以自行尝试,比如为100时,浏览器会在请求一段时间之后继续当前页面,500则为服务器内部错误等等
具体为什么会产生这样的结果,当然得把源码翻出来了
下面是HttpHeaderResult的一些成员变量,private的可以作为param的name属性
<div style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.53125px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div style="padding-left: 45px;"><div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[java]</strong> <a target=_blank href="javascript:void(0)#" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="javascript:void(0)#" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="javascript:void(0)#" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="javascript:void(0)#" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 483px; top: 2020px; width: 29px; height: 14px; z-index: 99;"></div></div></div><ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">static</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">final</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">long</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> serialVersionUID = 195648957144219214L; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">/** The default parameter */</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">public</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">static</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">final</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> String DEFAULT_PARAM = </span><span style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">"status"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">boolean</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> parse = </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">true</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> Map<String,String> headers; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> status = -</span><span class="number" style="margin: 0px; padding: 0px; border: none; color: rgb(192, 0, 0); background-color: inherit;">1</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">int</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> error = -</span><span class="number" style="margin: 0px; padding: 0px; border: none; color: rgb(192, 0, 0); background-color: inherit;">1</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">; </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> String errorMessage; </span></span></li></ol></div>
下面是具体执行操作过程,可以看到response.setStatus等操作
<div style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 936.53125px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;"><div style="padding-left: 45px;"><div style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);"><strong>[java]</strong> <a target=_blank href="javascript:void(0)#" title="view plain" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">view plain</a><a target=_blank href="javascript:void(0)#" title="copy" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">copy</a><a target=_blank href="javascript:void(0)#" title="print" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">print</a><a target=_blank href="javascript:void(0)#" title="?" style="color: rgb(160, 160, 160); text-decoration: none; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;">?</a><div style="position: absolute; left: 483px; top: 2361px; width: 29px; height: 14px; z-index: 99;"></div></div></div><ol start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">public</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> execute(ActionInvocation invocation) </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">throws</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> Exception { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> HttpServletResponse response = ServletActionContext.getResponse(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> ValueStack stack = ActionContext.getContext().getValueStack(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (status != -</span><span class="number" style="margin: 0px; padding: 0px; border: none; color: rgb(192, 0, 0); background-color: inherit;">1</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">) { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> response.setStatus(status); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">else</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (error != -</span><span class="number" style="margin: 0px; padding: 0px; border: none; color: rgb(192, 0, 0); background-color: inherit;">1</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">) { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (errorMessage != </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">null</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">) { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> String finalMessage = parse ? TextParseUtil.translateVariables( </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> errorMessage, stack) : errorMessage; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> response.sendError(error, finalMessage); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">else</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> response.sendError(error); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (headers != </span><span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">null</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">) { </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> <span style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">for</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> (Iterator iterator = headers.entrySet().iterator(); </span></span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> iterator.hasNext();) { </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> Map.Entry entry = (Map.Entry) iterator.next(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> String value = (String) entry.getValue(); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> String finalValue = parse ? TextParseUtil.translateVariables(value, stack) : value; </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> response.addHeader((String) entry.getKey(), finalValue); </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: rgb(85, 85, 85); line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li><li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(245, 250, 226); color: inherit; line-height: 18px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"> } </span></li></ol></div>
<strong><span style="font-size: 16px;">4.redirect
</span></strong>
重定向操作,与请求转发的区别看1的介绍
让客户端请求另外的网络资源,可以为action,也可以为视图资源
下面是apache的示例
1. <result name="success" type="redirect">
2. <param name="location">foo.jsp</param>
3. <param name="parse">false</param>
4. </result>
5.redirectAction
重定向至Action,与redirect的区别找了好久,但是也没发现比较权威的说明
最明显的区别当然是redirectAction只能请求action,如果请求视图资源会报错
然后还有个小区别就是redirectAction会为url添加.action后缀而redirect不会
有说redirectAction无法通过url传参,但是我测试时完全可以通过request获取到,
此处区别如果有哪位知道的麻烦告知,Thank you!
下面是apache的传参的示例
1. <package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters">
2. <-- Pass parameters (reportType, width and height) -->
3. <!--
4. The redirect-action url generated will be :
5. reportType=pie&width=100&height=100
6. >
7. <action name="gatherReportInfo" class="...">
8. <result name="showReportResult" type="redirect-action">
9. <param name="actionName">generateReport</param>
10. <param name="namespace">/genReport</param>
11. <param name="reportType">pie</param>
12. <param name="width">100</param>
13. <param name="height">100</param>
14. </result>
15. </action>
16. </package>
6.stream
这个返回类型主要用作下载文件或者在浏览器上显示PDF等文档
此处给一个显示PDF文档示例
项目web.xml中
1. <mime-mapping>
2. <extension>pdf</extension>
3. <mime-type>application/pdf</mime-type>
4. </mime-mapping>
struts.xml中
1. <action name="test" class="com.iss.action.TestAction">
2. <result name="success" type="stream">
3. <param name="contentType">application/pdf</param>
4. <param name="inputName">inputStream</param>
5. <param name="contentDisposition">filename="a.pdf"</param>
6. </result>
7. </action>
TestAction.java中
1. public class TestAction extends ActionSupport
2. {
3.
4. private InputStream inputStream;
5.
6.
7. public InputStream getInputStream()
8. {
9. return inputStream;
10. }
11.
12. @Override
13. public String execute() throws Exception
14. {
15. new FileInputStream("xxxxx/a.pdf");//要下载或显示的文件路径
16. return SUCCESS;
17. }
18. }
需要注意的地方是struts.xml中inputName的值要与TestAction中的get方法名相关,如在此处是getInputStream,inputName则为inputStream
7.plainText
响应以plain形式返回给客户端
截取源码的最重要的一部分
1. if (charset != null) {
2. "text/plain; charset="+charSet);
3. }
4. else {
5. "text/plain");
6. }
8.freemarker,velocity,xslt
没有尝试过,有兴趣的可以尝试下
写得很累。。。