struts2.0有那几种重定向的方式?
还有没有struts1.3里面的ActionForward()方法重定向?我要实现的功能是,一个action处理完业务  但是不确定要重定向到那个jsp去
要根据数据库的地址才能决定 配置文件只能控制一个 不能灵活的控制 请问怎么实现这样的重定向???

解决方案 »

  1.   

    可以,STRUTS2.0 在配置文件里 <result 标签可以用 *.jsp 符合多种传值页面。
      

  2.   

    2楼能说具体点么?
    小弟是个菜鸟。看的不是很明白 以前也没用过struts2.0.
      

  3.   

    struts2 框架有以下几种类型:
    <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中的变量,写在配置文件中
      

  4.   

    恩.. <result-type name="dispatcher 用这个进行跳转.楼主你说的那个问题,只是你的应用方面,需要从数据库中获取地址,你可以在应用中根据你的业务需求来解决.
      

  5.   

    <result-type name="redirect"  重定向
                 name="dispatcher"  转发
      

  6.   

    根据你的action的中return的结果对应不同的返回页面呀在result中实现<action name="">
    <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>
      

  7.   

    struts2重定向:1>.重定向JSP<action name="" method="" class="">
       <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
      

  8.   

    那在action的方法中怎样调用?
      

  9.   


    ActionForward forward = new ActionForward();
    path = "/games/main.jsp";
    path = path + "?gamemode=" + role.getGamemode();
    forward.setPath(path);
    forward.setRedirect(true);
    return forward;
    这样可以从action控制跳转路径,我写的个写死的,你根据你的数据拼装路径就行了
      

  10.   

    没有啊 ActionForward 属性了啊
    ActionForward forward = new ActionForward();也不行 new不出来 也没有说要导什么包啊 楼上的不是用的struts1.0的吧?
    我是问的struts2.0版本的啊.7楼8楼说了配置没说action怎么实现.
      

  11.   

    testAction:
    你在action中reutrn "failure";struts.xml
    在<action name="testAction" method="" class=""> 
      <result type="redirect" name="failure">重定向的页面</result> 
    </action这样就是重定向了
      

  12.   

    在 action中能获取到request吧...然后可以考虑通过 request来实现跳转吧....
      

  13.   

    这个中的ActionForward 是在struts1中出现的,你现在使用的struts2中当然找不到啦。
    你要使用的关于如何跳转就要这样得做的呀
    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 对应就可以啦
      

  14.   

    你的action实现ServletResponseAware接口,然后获取HttpServletResponse这是想怎么redirect都行了
      

  15.   


    嗯  
    欢迎加入!
    ------------------------
    qq群 59011611
    深圳外包.J2EE群
    qq群 43652320
    在线程序员论坛
      

  16.   

    可以这么解决。比如urlString存的是你从数据库中取出来要跳转的页面。
    在xml配置文件中你可以这么写。
      

  17.   

    晕,没写完就发了,在写下可以这么解决。比如urlString存的是你从数据库中取出来要跳转的页面。 
    在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>
      

  18.   

    <result name="welcome" type="redirect">
    /web/index.jsp
    </result>
    type="redirect"  设置这个属性就行了
      

  19.   

    不知道现在外面struts2用的多嘛?
      

  20.   

    楼主去查查吧,struts将servletAPI组件化了,可以在任何作为action中的类获取并使用它。
    既然Servlet本身就有dispather.findforward()和request.sendredirect(),那么struts2就一定能有楼主想要的转向。
      

  21.   

    <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>
      有两种,一个是redirect  另一个是forword 不过我建议用前者,因为这样可以过滤或者设置一些权限,而forword 有很多不安全,而且不稳定的因素在其中
      

  22.   


    支持,在你得某个action中写个变量在用OGNL就好了
      

  23.   


      我认为23楼的真正理解了lz的意思,至少转发到的页面是动态获得的
    ${urlString}能用在配置文件中么?我还真没这么用过呢,学习了呵呵~~~
     支持一下dragon1017 
      

  24.   

    顶23楼的,用这种OGNL表达式语言关联Action应该是最佳选择了!
      

  25.   

    struts2.0中从一个Action跳到另一个Action需要用标签:
    <result name="success" type="redirect">/ok.jsp</result>关于result标签type属性还有一下几种:
    "chain" 
    "dispatcher" 
    "freeer"
    "httpheader" 
    "redirectAction" 
    "stream" 
    "velocity" 
    "xslt" 
    "plainText" 
      

  26.   


    这个说的错的 在struts2里面 HttpServletResponse控制不了跳转方向
      

  27.   

    struts2 不能实现像struts1 那样的在action中重定向吗?
      

  28.   

    找到了,嘿嘿:
    http://www.chineselinuxuniversity.net/courses/application/articles/26252.shtml
      

  29.   

    @Override
    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;            }