如果要从默认模块切换到其它模块采用以下类似的URL
http://localhost:8080/toModule.do?prefix=/mouduleB&page=/index.do

解决方案 »

  1.   

    上面的是采用SwithAction(<action path="/toModule type=org.apache.struts.actions.SwitchAction")
      

  2.   

    就是我打开这个网站,它当然是默认的模块。我应该用什么方法,比如链接、ACTION等等,它的默认模块变成另一个模块。
      

  3.   

    to stephen129(破坏游戏的孩子)如果我想到mouduleB,是不是只需要写一次这句URL就行了,而不是每次都要加prefix=/mouduleB这个后缀?
      

  4.   


    可以这样,在index.jsp里
    <%@ taglib uri="/tags/struts-logic" prefix="logic" %>
    <logic:redirect forward="welcome"/>struts-config.xml里配置<action path="/welect"
        type="org.apache.struts.actions.ForwardAction"
        parameter="OtherJSP.jsp"
    />
      

  5.   

    可以这样,在index.jsp里
    <%@ taglib uri="/tags/struts-logic" prefix="logic" %>
    <logic:redirect forward="welcome"/>struts-config.xml里配置<action path="/welcome"
        type="org.apache.struts.actions.ForwardAction"
        parameter="OtherJSP.jsp"
    />
      

  6.   

    STRUTS的例子里好象是这样子:<html:link action="" module="">LINK</html:link>
      

  7.   

    TO:dddeee(dddeee)
    SwitchAction 类用于子应用模块之间的切换
    在STRUTS配置文件中:
    <action-mappings
       <action path="/toModule 
               type=org.apache.struts.actions.SwitchAction/>
               .......
    </action-mappings>
    SwitchAction类execute方法代码
     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
            throws Exception
        {
            String page = request.getParameter("page");
            String prefix = request.getParameter("prefix");
            if(page == null || prefix == null)
            {
                String message = messages.getMessage("switch.required");
                log.error(message);
                response.sendError(400, message);
                return null;
            }
            RequestUtils.selectModule(prefix, request, getServlet().getServletContext());
            if(request.getAttribute("org.apache.struts.action.MODULE") == null)
            {
                String message = messages.getMessage("switch.prefix", prefix);
                log.error(message);
                response.sendError(400, message);
                return null;
            } else
            {
                return new ActionForward(page);
            }
        }参数:prefix(指定模块的前缀)
          page(指定被请求组件的URL)
    如果你不想每次都加这两个参数,你可以拓展这个类