今天在用到Struts开发一个应用的时候遇到错误:
exception
javax.servlet.ServletException: Cannot retrieve mapping for action /showProLists
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.apply.showProList_jsp._jspService(showProList_jsp.java:193)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
起初,怀疑是:struts-config.xml里的action配置错误,后来仔细检查,发现无错误,排除此疑!
用到的action:
public class ShowProListAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse Response) {
// ShowProListForm form = (ShowProListForm)actionForm;
String temp=request.getParameter("testSecID");
int ID=Integer.parseInt(temp);
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+ID);
ShowProListDAO prolistDAO=new ShowProListDAO();
ArrayList arr=new ArrayList();
arr=prolistDAO.getProList(ID);
if(arr==null){
return mapping.findForward("null");
}
if(arr !=null){
if(arr.size()==0){
return mapping.findForward("null");
}
else{
request.setAttribute("showProList",arr);
request.setAttribute("stationID",temp);
ArrayList proList=(ArrayList)request.getAttribute("showProList");
for(int i=0;i<proList.size();i++){
ShowProList projects=(ShowProList)proList.get(i);
System.out.println(projects.getProjectName());
}
System.out.println(temp);
return mapping.findForward("success");
}
}
return mapping.findForward("fail");
}
}
System.out.println(temp)和System.out.println(projects.getProjectName());
均正常输出。怀疑,return mapping.findForward("success")怀疑这一步跳转错误?
修改过若干遍struts-config.xml文件,依旧未果!!!!!
最后,dxian来帮忙检查,发现实际上,该action类,完全通过了。是在跳转到下个jsp页面后,jsp页面里有一表单form:
部分代码如下:
<html:form action="showProLists" method="post">showProListAction.do
<br><br>
<%
ArrayList proList=(ArrayList)request.getAttribute("showProList");
%>
因为,刚开始写该jsp页面时,是copy了一个过来直接改的,忘记把里的form去掉!结果,发生了错误!
至此,该问题解决!先前都没遇到过这个情况,花了好多时间在这个上面。
末了,要感谢下帮过我无数次的 dxian:)