struts2.0有那几种重定向的方式?
还有没有struts1.3里面的ActionForward()方法重定向?我要实现的功能是,一个action处理完业务 但是不确定要重定向到那个jsp去
要根据数据库的地址才能决定 配置文件只能控制一个 不能灵活的控制 请问怎么实现这样的重定向???
还有没有struts1.3里面的ActionForward()方法重定向?我要实现的功能是,一个action处理完业务 但是不确定要重定向到那个jsp去
要根据数据库的地址才能决定 配置文件只能控制一个 不能灵活的控制 请问怎么实现这样的重定向???
解决方案 »
- jsp页面内容重复,超诡异
- 500错误的问题???
- struts 的actionForm 执行validate验证问题--很奇怪————急!!!!!!!!!!
- 请问JavaBean与Servlet到底有什么区别?
- 无法显示网页背景图片
- 在jsp页面中如何实现WEB页面随着图片的大小而改变,图片要正好完全显示
- 高手指教:关于JSP类型转换的问题
- Oracle 报错 Io 异常: Connection refused
- win98环境下不能运行tomcat吗?谢谢!
- "tomcat+jive"为何无法显示汉字!
- 【求助】关于action传递ArrayList给JSP的问题
- 我的eclipse打不开类了
小弟是个菜鸟。看的不是很明白 以前也没用过struts2.0.
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="freeer" class="org.apache.struts2.views.freeer.FreeerResult"/>
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
其中redirect与ActionForward()有点类似.用数据库中的网址,那就把model中的变量,写在配置文件中
name="dispatcher" 转发
<result name="c1">/**.jsp</result>
<result name="c2">/**.jsp</result><result name="c2">/**.jsp</result>
<result name="c4">/**.jsp</result>
</action>
<action name="">
<result name="c1" type="redirect">*.action</result>
<result name="c2 type="chain">methodName</result>
<result name="c4" type="redirect-action">mathodName</result>
</action>
<result type="redirect">重定向jsp</result>
</action2>.重定向Action<action name="" method="" class="">
<result type="redirectAction">
<param name="actionName">重定向ActionName</param>
<param name="namespace">重定向ActionName所在命名空间</param>
</result>
</action
ActionForward forward = new ActionForward();
path = "/games/main.jsp";
path = path + "?gamemode=" + role.getGamemode();
forward.setPath(path);
forward.setRedirect(true);
return forward;
这样可以从action控制跳转路径,我写的个写死的,你根据你的数据拼装路径就行了
ActionForward forward = new ActionForward();也不行 new不出来 也没有说要导什么包啊 楼上的不是用的struts1.0的吧?
我是问的struts2.0版本的啊.7楼8楼说了配置没说action怎么实现.
你在action中reutrn "failure";struts.xml
在<action name="testAction" method="" class="">
<result type="redirect" name="failure">重定向的页面</result>
</action这样就是重定向了
你要使用的关于如何跳转就要这样得做的呀
public String toLogin() throws Exception
{
try {
Map<String, Register> session=ActionContext.getContext().getSession();
register = authorService.loginValid(userName, passWord);
if(register !=null){
session.put("register",register);
return SUCCESS;
}else{
addActionError("<font color='red'>用户名/密码不匹配</font>");
return "failure";
}
} catch (Exception e) {
// TODO: handle exception
this.setTip("<font color='red'>对不起,系统出现故障,请稍后再登录!</font>");
e.printStackTrace();
return "failure";
}
}看见return 后面的返回值没有呀 他要和你的在struts.xml中的
<action name="login" class="loginAction" method="toLogin">
<result name="input">/login/authorlogin.jsp</result>
<result name="failure">/login/authorlogin.jsp</result>
<result name="success" type="redirect">
countmessage.action
</result>
</action>
中的name 对应就可以啦
嗯
欢迎加入!
------------------------
qq群 59011611
深圳外包.J2EE群
qq群 43652320
在线程序员论坛
在xml配置文件中你可以这么写。
在xml配置文件中你可以这么写。 <action name="***" class="***" method="****">
<result name="success" type="redirect">${urlString}</result>
</action>假设我的urlString 为http://www.sohu.com/
他就跳转到sohu的网页去了。是跳转到外站必须要加上http://,本地工程就不用了,得到的字符串中路径什么的都是对的就可以了。
如果你的urlString为另外一个action的名字,假设为123.action,也是这样的写法。
如果你的urlString是<action name="qwer" class="***" method="****">中的name的值qwer 就应该这样写<action name="***" class="***" method="****">
<result name="success" type="redirectAction">${urlString}</result>
</action>
/web/index.jsp
</result>
type="redirect" 设置这个属性就行了
既然Servlet本身就有dispather.findforward()和request.sendredirect(),那么struts2就一定能有楼主想要的转向。
<result name="input">/login/authorlogin.jsp</result>
<result name="failure">/login/authorlogin.jsp</result>
<result name="success" type="redirect">
countmessage.action
</result>
</action>
有两种,一个是redirect 另一个是forword 不过我建议用前者,因为这样可以过滤或者设置一些权限,而forword 有很多不安全,而且不稳定的因素在其中
支持,在你得某个action中写个变量在用OGNL就好了
我认为23楼的真正理解了lz的意思,至少转发到的页面是动态获得的
${urlString}能用在配置文件中么?我还真没这么用过呢,学习了呵呵~~~
支持一下dragon1017
<result name="success" type="redirect">/ok.jsp</result>关于result标签type属性还有一下几种:
"chain"
"dispatcher"
"freeer"
"httpheader"
"redirectAction"
"stream"
"velocity"
"xslt"
"plainText"
这个说的错的 在struts2里面 HttpServletResponse控制不了跳转方向
http://www.chineselinuxuniversity.net/courses/application/articles/26252.shtml
public String list() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
String loginName = request.getParameter("j_username");
String password = request.getParameter("j_password");
HttpSession session = request.getSession();
session.setAttribute("username", loginName);
session.setAttribute("password", password);
//你要转向的页面的地址. String url = new String( ("../j_spring_security_check?j_username="
+java.net.URLEncoder.encode(loginName)
+"&j_password="+password).getBytes("UTF-8"),"ISO8859_1");
//你要转向的页面的地址.
HttpServletResponse response = ServletActionContext.getResponse();
response.sendRedirect(url);
//重定向后,别忘了返回null值,而不能再返回return
//mapping.findForward("****");
return null;
//return SUCCESS; }