我有两个不同的页面,都需要使用同一个Action 请问该如何写?我想很久都不能想出来,请大家帮帮忙
解决方案 »
- 求传智播客方立勋javaweb11讲后面的视频。。。
- 求高手帮忙写个正则表达式
- servlet/jsp运行出错,请高手帮帮忙
- jbuilder+weblogic???????????
- 本人最近在学习 web service , 关于访问权限的控制有很多疑惑,希望高人帮忙解答!
- 关于xml校验的问题:dtd?schema?
- 关于JDOM的问题
- JSP中图片不能显示问题!!
- 请问怎样通过程序,把 jsp 转成 servlet ?
- 初学者问题:EJB的LocalHome接口与Home接口有什么不同它们分别有什么作用.
- 大家好,我想问一下,用jsp做网站,不用框架,安全么
- struts1.2中 actionform的生命周期
<action name="actionName" class="Action">
<result name="方法的返回值1">WEB-INF/jsp/对应的页面</result>
<result name="方法的返回值2">WEB-INF/jsp/对应的页面</result>
</action>
<forward name="build" path="/alarmstat/alarmstatbuild.jsp"/>
<forward name="buildadd" path="/alarmstat/alarmstatbuildadd.jsp" />
<forward name="hasbuild" path="/alarmstat/alarmstathasbuild.jsp" />
<forward name="alarmstats" path="/alarmstat/alarmstats.jsp" />
</action>
请求页面直接引用action的path不就行啦嘛
跟一个页面跳到一个action是一样的
public class Client_LoginAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("userName");
String uid = request.getParameter("pwd");
String path = "";
ActionErrors errors = new ActionErrors();
if(OperationDao.getOperDao().Lgoin(name, uid)){
path = "success";
}else{
path="error";
}
return mapping.findForward(path);
}
}
然后是struts-config.xml文件里面的配置信息 <global-forwards >
<forward name="success" path="/MyJsp.jsp" />
<forward name="error" path="/error.jsp" />
</global-forwards >
你应该多看哈书...看书看明白了以后印象就很深...!
直接在你要跳转的页面<form action="">写上你在struts-config.xml中配置的action
如果你的意思是要在同一个action中处理两个或多个不同页面的请求,你应该使用"dispatchaction"。
这是 struts1的写法把. 不过最好不要用系统给的名称,把 execute 名称改成你自定义的名称, success,error 两个也要改起个和页面名称差不多的名字,这样比较不会乱.
struts2 中也差不多,这样调用就是写法略不同.
好改啊...
?如果是一样的还写2个页做什么?
建议:1、写2个action
2、返回值不一样的话就做个判断,如果是页1的值就写return "page1";如果是页2的值就写return "page2";错误页就写return "error";不一定就得写2个返回值!!
struts.xml文件的result里接一下,如果是page1的话就写你页1的地址如:page1.jsp.下面的如上,我这个是struts2的做法,可能和你的有的出入,但是思想是差不多的!希望对你有帮助。