struts2怎么做forward-action?

xwy1982 2008-09-24 08:52:43
先说明下我现在的情况
<result name="addaction" type="redirect">
${addAction}
</result>
${addAction}的值是像这样的goodsdir.action;jsessionid=07EFF440B06BC7B02F1912BD1A3BDE5B?action=addsale.action_1222258297312
这样是重定向的做的,也就是会先发一个这样的包
HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Location: goodsdir.action;jsessionid=4DCD880CA412CFD7D8E3483236EF6430?action=addsale.action_1222259550468
Content-Length: 0
Date: Wed, 24 Sep 2008 12:32:34 GMT
然后客户端再去请求goodsdir.action;jsessionid=4DCD880CA412CFD7D8E3483236EF6430?action=addsale.action_1222259550468
我想不用重定向,直接转发过去,要怎么做?
试了一下type="redirect-action"参数会丢掉
chain不能把参数通过url传
所以想有没类似forward-action这样的方式
...全文
3305 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangyi123 2008-09-25
  • 打赏
  • 举报
回复
学习,帮顶
angel_bear 2008-09-25
  • 打赏
  • 举报
回复
type="redirect" 去到默认不就是重定向嘛。貌似……
yeah920 2008-09-25
  • 打赏
  • 举报
回复
帮你顶一下。
xwy1982 2008-09-25
  • 打赏
  • 举报
回复
2楼:
这个不能用于action,会提示资源找不到
3楼:
就是不要重定向,我需要请求转发的方式

这里再解释下:
是这样的
比如
浏览器去请求a.action这样页面
服务器会回应一个重定向的包
浏览器在去请求b.action?fs=fsfds这样的页面
最终显示出来

我需要的是,不要中间的过程,请求a.action,直接返回b.action?fs=fsfds的内容
不知道这样解释清楚了没有,呵
jy02411368 2008-09-25
  • 打赏
  • 举报
回复
楼主对网络很熟悉。。。要问有经验的人了。。。
yaray 2008-09-25
  • 打赏
  • 举报
回复
简单说明一下result的name属性和type属性:
SUCCESS:Action正确的执行完成,返回相应的视图,success是name属性的默认值;
NONE:表示Action正确的执行完成,但并不返回任何视图;
ERROR:表示Action执行失败,返回到错误处理视图;
INPUT:Action的执行,需要从前端界面获取参数,INPUT就是代表这个参数输入的界面,一般在应用中,会对这些参数进行验证,如果验证没有通过,将自动返回到该视图;
LOGIN:Action因为用户没有登陆的原因没有正确执行,将返回该登陆视图,要求用户进行登陆验证。
dispatcher:请求转发,底层调用RequestDispatcher的forward()或include()方法,dispatcher是type属性的默认值,通常用于转向一个JSP,localtion指定JSP的位置,parse如果为false表示location的值不会被当作OGNL解析,默认为true;
redirect:重定向,新页面无法显示Action中的数据,因为底层调用response.sendRedirect("")方法,无法共享请求范围内的数据,参数与dispatcher用法相同;
redirect-action:重定向到另一个Action,参数与chain用法相同,允许将原Action中的属性指定新名称带入新Action中,可以在Result标签中添加<param name=”b”>${a}</param>,这表示原Action中的变量a的值被转给b,下一个Action可以在值栈中使用b来操作,注意如果值是中文,需要做一些编码处理,因为Tomcat默认是不支持URL直接传递中文的!
velocity:使用velocity模板输出结果,location指定模板的位置(*.vm),parse如果为false,location不被OGNL解析,默认为true;
xslt:使用XSLT将结果转换为xml输出,location指定*.xslt文件的位置,parse如果为false,location不被OGNL解析,默认为true,matchingPattern指定想要的元素模式,excludePattern指定拒绝的元素模式,支持正则表达式,默认为接受所有元素;
httpheader:根据值栈返回自定义的HttpHeader,status指定响应状态(就是指response.sendError(int i)重定向到500等服务器的状态页),parse如果为false,header的值不会被OGNL解析,headers,加入到header中的值,例如:<param name=”headers.a”>HelloWorld</param>,可以加多个,这些键-值组成HashMap;
freemaker:用freemaker模板引擎呈现视图,location指定模板(*.ftl)的位置,parse如果为false,location的值不会被OGNL解析,contentType指定以何中类型解析,默认为text/html;
chain:将action的带着原来的状态请求转发到新的action,两个action共享一个ActionContext,actionName指定转向的新的Action的名字,method指定转向哪个方法,namespace指定新的Action的名称空间,不写表示与原Action在相同的名称空间;skipActions指定一个使用 , 连接的Action的name组成的集合,一般不建议使用这种类型的结果;
stream:直接向响应中发送原始数据,通常在用户下载时使用,contentType指定流的类型,默认为text/plain,contentLength以byte计算流的长度,contentDisposition指定文件的位置,通常为filename=”文件的位置”,input指定InputStream的名字,例如:imageStream,bufferSize指定缓冲区大小,默认为1024字节;
plaintext:以原始文本显示JSP或者HTML,location指定文件的位置,charSet指定字符集;
xwy1982 2008-09-25
  • 打赏
  • 举报
回复
看来只能用chain方式了
把要传递的参数在两个action里都定义一个同样的变量名,会默认去get和set
szhshaozhihua 2008-09-25
  • 打赏
  • 举报
回复
可以试试这杨写
<html:form action=TheAction?action=execute" method="post">

</html:form>

config.xml 需要对应的FormBean 和 Forward跳转


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
@SuppressWarnings("unused")
DynaActionForm loginForm = (DynaActionForm) form;// TODO Auto-generated method stub
String target="login";
return mapping.findForward(target);
}

}
rubysun2008 2008-09-25
  • 打赏
  • 举报
回复
没懂这意思
sebatinsky 2008-09-25
  • 打赏
  • 举报
回复
不是说不能重定向,和forward-action,要配合使用,如果你是几个转向,我说的是拦截器,可能不知道你是不是说的这个意思,如果纯粹是跳转,我想你也会了,直接指定result就可以了,然后可以加上些参数,指定不同的转向,如果是要用的拦截就可以参看max写到东西,呵呵,
<package name="interceptor" extends="struts-default">
<interceptors>
<interceptor name="auth" class="interceptor.AuthorizationInterceptor"></interceptor>
</interceptors>
<action name="Timer" class="interceptor.TimerInterceptorAction">
<interceptor-ref name ="timer"/>
<result >/Timer.jsp</result>
</action >
<action name="Login" class="interceptor.Login">
<result type="chain">AuthorizatedAccess</result>
</action>
<action name="AuthorizatedAccess" class="interceptor.AuthorizatedAccess">
<interceptor-ref name="auth"></interceptor-ref>
<result name="login">/Login.jsp</result>
<result name="success">/ShowUser.jsp</result>
</action>
</package>
这里贴了一点,你看看,
程序员长弓 2008-09-24
  • 打赏
  • 举报
回复
struts里面没有楼主说的forward-action
贴个例子:
<package name="main" extends="struts-default">
<action name="index">
<result>login.jsp</result>
</action>
<action name="welcome">
<result>welcome.jsp</result>
</action>
<action name="login" class="loginAction">
<result name="success">welcome.jsp</result>
<result name="input">login.jsp</result>
</action>
<action name="logout" class="logoutAction">
<result name="success">login.jsp</result>
</action>
<action name="register" class="registerAction">
<result name="success">login.jsp</result>
<result name="input">register.jsp</result>
</action>
</package>
wipe_tear 2008-09-24
  • 打赏
  • 举报
回复
没明白啥意思,知识太少了
帮忙顶了

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧