81,091
社区成员
发帖
与我相关
我的任务
分享
<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>
<%@ 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>
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为自建的异常类;
public class UserNameService {
public void UserNameLogic() throws UserNameException{
}
}
public class UserNameException extends Exception {
public UserNameException(){}
}