用myEclipse+struts做的个验证struts-config中exception标签的例子,其中用了DynaActionForm,没有写专门的actionForm类,我的action中并没有调用actionForm,只是抛出了个自定义的异常类。
struts-config文件
<struts-config> <form-beans>
<form-bean name="LoginDynActionForm"
type="org.apache.struts.action.DynaActionForm">
<form-property name="sex" type="java.lang.String" />
<form-property name="userName" type="java.lang.String" />
<form-property name="age" type="java.lang.String" />
<form-property name="email" type="java.lang.String" />
<form-property name="passWord" type="java.lang.String" />
</form-bean>
</form-beans>
<action-mappings>
<action input="SampleJSP.jsp" path="/SampleAction"
scope="request" type="skin.struts.action.SampleAction"
name="LoginDynActionForm"
validate="false">
<exception key="userNameException" path="/SampleJSP.jsp"
type="skin.struts.exception.UserNameException" />
</action>
</action-mappings> <message-resources parameter="resources.application" /></struts-config>
显示页面SampleJSP文件:
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page language="java"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html>
<head>
<title>JSP for SimpleForm</title>
</head>
<body>
<html:errors/><p/>
<html:form action="SampleAction.do">
userName : <html:text property="userName"/><br/>
passWord : <html:password property="passWord"/><br/>
sex: <html:select property="sex">
     <html:option key="F" value="F"/>
     <html:option key="M" value="M"/>
      </html:select><br/>
      age : <html:text property="age"/><br/>
      email : <html:text property="email"/><br/>
      <html:submit/><html:cancel/>
     </html:form>
</body>
</html>
action类:
public class SampleAction extends Action { @Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
UserNameService userNameService = new UserNameService();
userNameService.UserNameLogic();
return null;
}}其中UserNameService是自建的处理逻辑类,只有一个UserNameLogic()方法,方法为throw new UserNameException("UserName"),UserNameException为自建的异常类;
在myEclipse中搭建了环境,访问http://127.0.0.1:8080/exception/SampleJSP.jsp出现Form bean not specified on mapping for action: "SampleAction.do"
问题。
求助~~~~

解决方案 »

  1.   

    楼主,我用的Eclipse是7.0的,按照你的路径访问出来的就是SampleJSP.jsp的页面,没有出现你的问题。有一点点跟你的不一样,UserNameService中的方法UserNameLogic()是throws,而不是throw:public class UserNameService {
    public void UserNameLogic() throws UserNameException{
    }
    }
    UserNameException 如下:public class UserNameException extends Exception {

    public UserNameException(){}

    }
    访问后的页面如下: