struts DispatchAction无法使用 我的action也继承了DispatchAction 也配置了 parameter="command",带参数无法后却无法使用里面的方法,直接过 我一直都那样写 ,今天新写个项目就出现这个问题 大家帮帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在用DispatchAction的时候别忘记了在STRUTS-CONFIG中的<action>属性加parameter="method"还有<html:form>和普通的<form>是有区别的,在用form提交表单的时候别忘记要加范围method="post",不然也会有错另外在action.do/method=XXXX这个中间不要有空格楼主仔细检查检查看看 1.<action>属性加了parameter="method" 2.我是用<form>也加了method="post" 3.action.do/method=XXXX这个中间没有空格真的很奇怪 “直接过”是什么意思?看看参数值和方法名是否对应上了再不行设断点看看行不行,如果设断点也没有反应,不进方法里,有可能是ActionForm里的验证方法有判空条件。 。那就真的很奇怪了,你清空下tomcat安装目录(如果不是安装版,找根目录;另外有需要tomcat安装版的朋友可以去我的资源里看看)下的work文件夹,webapps文件夹下的该项目也删除掉重新用tomcat部署该项目,然后重启tomcat看看应该没什么问题 我的DispatchAction 有save、find这些方法,当我save完转到跳转到find就直接进入input指向的页面,如果我先find在跳转其他也相同 如果我带的参数值在DispatchAction 没有的话应该指向unspecified这个方法,可是也直接来input指向的页面 好像这action类就是个普通的action,只能用一次一样 我直接用a标签访问 也input指向的页面 我用strutsTest 测试不管带什么参数都不会执行这个action类 也没有任务异常 你说你是先进到save方法后又跳转到find方法,那么你的跳转必须是重定向的,要不就会到input页面 <forward name="find" path="/user.do?method=find" redirect="true"></forward> 就是重定向的啊 strutsTest测试不管带什么参数都不会执行里面任务一个方法 1.actionpublic class QuestionAction extends DispatchAction { @Override protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("-----------questionAction.unspecified()-----------"); ActionForward af=new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true); return af; } private QuestionServer quesServer; private Question question; private Item item; public void setItem(Item item) { this.item = item; } public void setQuesServer(QuestionServer quesServer) { this.quesServer = quesServer; } public void setQuestion(Question question) { this.question = question; } public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("-----add------"); return null; } public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { QuestionActionForm qaf=(QuestionActionForm)form; BeanUtils.copyProperties(question, qaf); Set itemSet=new HashSet<Item>(0); for(String str: qaf.getItemName()){ Item item=new Item(); item.setItemName(str); item.setResult(0); item.setQuestion(question); itemSet.add(item); } question.setItem(itemSet); quesServer.save(question); ActionForward af=new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true); return af; } public ActionForward findAll(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { QuestionActionForm qaf=(QuestionActionForm)form; int pageNo=qaf.getPageNo(); PageModel pageModel=quesServer.findAll(pageNo); request.setAttribute("pageModel", pageModel); return mapping.findForward("listQuestion"); }} public class QuestionAction extends DispatchAction { @Override protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("-----------questionAction.unspecified()-----------"); ActionForward af=new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true); return af; } private QuestionServer quesServer; private Question question; private Item item; public void setItem(Item item) { this.item = item; } public void setQuesServer(QuestionServer quesServer) { this.quesServer = quesServer; } public void setQuestion(Question question) { this.question = question; } public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("-----add------"); return null; } public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { QuestionActionForm qaf=(QuestionActionForm)form; BeanUtils.copyProperties(question, qaf); Set itemSet=new HashSet<Item>(0); for(String str: qaf.getItemName()){ Item item=new Item(); item.setItemName(str); item.setResult(0); item.setQuestion(question); itemSet.add(item); } question.setItem(itemSet); quesServer.save(question); ActionForward af=new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true); return af; } public ActionForward findAll(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { QuestionActionForm qaf=(QuestionActionForm)form; int pageNo=qaf.getPageNo(); PageModel pageModel=quesServer.findAll(pageNo); request.setAttribute("pageModel", pageModel); return mapping.findForward("listQuestion"); } 不好意思卡了下 发了两次<action path="/Question/addQuestion2" name="quseForm" input="/Question/addQuestion2.jsp" scope="request" parameter="command"> <forward name="listQuestion"path="/Question/listQuestions.jsp" /></action> ActionForward af=new ActionForward("/addQuestion2.do?command=findAll&pageNo=1",true); 你这是不是少写了一个/阿 new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true); 你这个后面的true是表示重定向吗,我很少用这个一般都是配置到struts中去的 要不你把转向配置到struts中看看行不 恩 添加true表示重定向 我在strutsTest中,应该是会执行unspecified。这个能在struts里配置?public void testQuestion(){ this.addRequestParameter("pageNo", "1"); this.addRequestParameter("command", "aa"); this.setRequestPathInfo("/Question/addQuestion2.do"); this.actionPerform();} unspecified方法是当你没有command参数时候调用的方法撒,不需要配置吧 谢谢各位的回答问题终于解决的了验证框架出了问题,所以没有都往input跳呵呵 人感冒晕乎乎的 如何用Ip地址访问? 在jsp里关联查询怎么会是空值? 初级的请教jsp 关于对数据排名问题! 求助:重定向页面与传递数据,失败! 在写jsp的时候有没有工具让关键字可以变色呢 radio检查框的问题,比较简单,着急用,马上结分 初学jsp,欲找师傅一名! 讨论:用jsp/servlet或xml/xslt建立站点,孰适孰优... ... 请问在TOMCAT中BEAN或者是SERVLET的类文件究竟应该放在哪个目录下??谢谢! 小问题帮忙解决 JSF和Struts2是可以互相替换的架构吗?能不能合二为一的?
还有<html:form>和普通的<form>是有区别的,在用form提交表单的时候别忘记要加范围method="post",不然也会有错
另外在action.do/method=XXXX这个中间不要有空格楼主仔细检查检查看看
1.<action>属性加了parameter="method"
2.我是用<form>也加了method="post"
3.action.do/method=XXXX这个中间没有空格
真的很奇怪
“直接过”是什么意思?
看看参数值和方法名是否对应上了
再不行设断点看看行不行,如果设断点也没有反应,不进方法里,有可能是ActionForm里的验证方法有判空条件。
那就真的很奇怪了,你清空下tomcat安装目录(如果不是安装版,找根目录;另外有需要tomcat安装版的朋友可以去我的资源里看看)下的work文件夹,webapps文件夹下的该项目也删除掉
重新用tomcat部署该项目,然后重启tomcat看看
应该没什么问题
如果我带的参数值在DispatchAction 没有的话应该指向unspecified这个方法,可是也直接来input指向的页面
好像这action类就是个普通的action,只能用一次一样
我直接用a标签访问 也input指向的页面
也没有任务异常
strutsTest测试不管带什么参数都不会执行里面任务一个方法
@Override
protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("-----------questionAction.unspecified()-----------");
ActionForward af=new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true);
return af;
}
private QuestionServer quesServer;
private Question question;
private Item item;
public void setItem(Item item) {
this.item = item;
}
public void setQuesServer(QuestionServer quesServer) {
this.quesServer = quesServer;
}
public void setQuestion(Question question) {
this.question = question;
}
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("-----add------");
return null;
}
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
QuestionActionForm qaf=(QuestionActionForm)form;
BeanUtils.copyProperties(question, qaf);
Set itemSet=new HashSet<Item>(0);
for(String str: qaf.getItemName()){
Item item=new Item();
item.setItemName(str);
item.setResult(0);
item.setQuestion(question);
itemSet.add(item);
}
question.setItem(itemSet);
quesServer.save(question);
ActionForward af=new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true);
return af;
}
public ActionForward findAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
QuestionActionForm qaf=(QuestionActionForm)form;
int pageNo=qaf.getPageNo();
PageModel pageModel=quesServer.findAll(pageNo);
request.setAttribute("pageModel", pageModel);
return mapping.findForward("listQuestion");
}
}
@Override
protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("-----------questionAction.unspecified()-----------");
ActionForward af=new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true);
return af;
}
private QuestionServer quesServer;
private Question question;
private Item item;
public void setItem(Item item) {
this.item = item;
}
public void setQuesServer(QuestionServer quesServer) {
this.quesServer = quesServer;
}
public void setQuestion(Question question) {
this.question = question;
}
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("-----add------");
return null;
}
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
QuestionActionForm qaf=(QuestionActionForm)form;
BeanUtils.copyProperties(question, qaf);
Set itemSet=new HashSet<Item>(0);
for(String str: qaf.getItemName()){
Item item=new Item();
item.setItemName(str);
item.setResult(0);
item.setQuestion(question);
itemSet.add(item);
}
question.setItem(itemSet);
quesServer.save(question);
ActionForward af=new ActionForward("addQuestion2.do?command=findAll&pageNo=1",true);
return af;
}
public ActionForward findAll(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
QuestionActionForm qaf=(QuestionActionForm)form;
int pageNo=qaf.getPageNo();
PageModel pageModel=quesServer.findAll(pageNo);
request.setAttribute("pageModel", pageModel);
return mapping.findForward("listQuestion");
}
<action path="/Question/addQuestion2"
name="quseForm"
input="/Question/addQuestion2.jsp"
scope="request"
parameter="command">
<forward name="listQuestion"path="/Question/listQuestions.jsp" />
</action>
public void testQuestion(){
this.addRequestParameter("pageNo", "1");
this.addRequestParameter("command", "aa");
this.setRequestPathInfo("/Question/addQuestion2.do");
this.actionPerform();
}
问题终于解决的了
验证框架出了问题,所以没有都往input跳
呵呵 人感冒晕乎乎的