STRUTS多模块开发中,怎么从默认模块,跳到另一个模块呢? 如果要从默认模块切换到其它模块采用以下类似的URLhttp://localhost:8080/toModule.do?prefix=/mouduleB&page=/index.do 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上面的是采用SwithAction(<action path="/toModule type=org.apache.struts.actions.SwitchAction") 就是我打开这个网站,它当然是默认的模块。我应该用什么方法,比如链接、ACTION等等,它的默认模块变成另一个模块。 to stephen129(破坏游戏的孩子)如果我想到mouduleB,是不是只需要写一次这句URL就行了,而不是每次都要加prefix=/mouduleB这个后缀? 可以这样,在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"/> 可以这样,在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"/> STRUTS的例子里好象是这样子:<html:link action="" module="">LINK</html:link> 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)如果你不想每次都加这两个参数,你可以拓展这个类 spring注入不了对象、报空指针异常 我的TOMCAT中马了!!!求解决 zip md5 asc 后缀都代表什么样的文件 Got minus one from a read call ..程序运行一半报错.... 要做单点登陆哪样方式比较好? 大吼一声:我不想把SQL语句写入JAVA,应该怎么办? 关于log4j的使用! 如何在WEBLOGIC 中设置与weblogic同时启动的类? 想开发一个三层的网站,请高手推荐几本实用的好书! 中间件有几种? 请问一下关于使用javamail发送带链接的普通邮件问题 重大苦脑,请求急救,在线等待,关心tomcat问题
可以这样,在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"
/>
<%@ 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"
/>
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)
如果你不想每次都加这两个参数,你可以拓展这个类