如和在Struts1中一个Action实现多个业务逻辑 如和在Struts1中一个Action实现多个业务逻辑,怎么样实现会比较好些 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你们看看我的代码 JSP的:<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";response.sendRedirect("dispStudent.do?method=dispStudent");%>Action配置文件<action path="/dispStudent" parameter="method" attribute="studentForm" name="studentForm" type="com.Struts1.Action.StudentAction" > <forward name="success" path="/index.jsp" /> </action> Action类package com.Struts1.Action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction;public class StudentAction extends DispatchAction { public ActionForward execute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {// String method = request.getParameter("method");// // if("dispStudent".equals(method))// this.dispStudent(mapping, actionForm, request, response); System.out.println("ccccccccc"); return mapping.findForward(""); } //显示所有的学生信息 public ActionForward dispStudent(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("ddddddddddd"); return mapping.findForward("success"); }} 现在时我运行 上面得JSP代码的时候就跳转的这个地址 然后就没有反应了。http://localhost:8088/Struts1/dispStudent.do?method=dispStudent 你确认转到指定的action了吗,如果转到了指定的action应该可以转到指定的页面,如果不能转到指定的action,你看下你的连接或者是表单,这里常常可能因为单引号或者双引号就会引起错误。 你用DispatchAction 的时候不能使用execute方法,不然它只会进到这个方法里面的,不管你写了多少其他方法都没有!把这个execute的名字改掉吧! 恩处理好了,去掉execute方法了,如果加这个方法的话,应该调用一下父类的execute方法吧 要把execute方法名字改成其他方法名,然后在配置文件对应的action中增加parameter属性,值为方法名,也可以继承MappingDispatchAction,这个更好用! 我的理解是让一个action实现多个业务逻辑,如果是这样的话,可不可以这样?绑定的from里,添加一个actionType属性在提交时,添加actionType的属性然后在action中,可以添加String strActionType = form.getActionType();if("Init".equals(strActionType)){ //TODO:执行从菜单进入该action的操作}else if("Edit".equals(strActionType)){ //TODO:编辑...}..... 我就是使用DispacAction的,配置文件,什么都是好的,为什么就是不进action。谁有关于这个的例子,分享下,给我看看。谢谢啦 利用JXL导出为Excel,怎么操作输入流 ajax问题 jnative 调用动态链接库参数问题? 如何修改Sping源码 Struts连接数据源问题 EJB请教!谢谢 将javabean存入session会不会占很多资源. 谁能给一个rowset.jar的有效下载地址? 对WebServices有何理解 EJB和JavaBean的最大区别是什么? 自动运行 txt 文件中的java代码 使用My97DatePicker时间控件取不到时间的时、分、秒值
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
response.sendRedirect("dispStudent.do?method=dispStudent");
%>
Action配置文件
<action path="/dispStudent"
parameter="method"
attribute="studentForm"
name="studentForm"
type="com.Struts1.Action.StudentAction"
>
<forward name="success" path="/index.jsp" />
</action> Action类
package com.Struts1.Action;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;public class StudentAction extends DispatchAction {
public ActionForward execute(ActionMapping mapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) throws Exception {// String method = request.getParameter("method");
//
// if("dispStudent".equals(method))
// this.dispStudent(mapping, actionForm, request, response);
System.out.println("ccccccccc");
return mapping.findForward("");
} //显示所有的学生信息
public ActionForward dispStudent(ActionMapping mapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("ddddddddddd");
return mapping.findForward("success");
}
}
MappingDispatchAction,这个更好用!
绑定的from里,添加一个actionType属性
在提交时,添加actionType的属性
然后在action中,可以添加
String strActionType = form.getActionType();
if("Init".equals(strActionType)){
//TODO:执行从菜单进入该action的操作
}else if("Edit".equals(strActionType)){
//TODO:编辑...
}.....