Struts--Action开发
1.使用默认的Action2.扩展DispatchAction,进行自动分发
Action中添加的方法
public class UsrAction extends DispatchAction {public ActionForward login(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {UsrForm usrForm = (UsrForm) form;... ...}} 修改配置文件
<action-mappings><action attribute="usrForm" input="/login.jsp" name="usrForm"path="/usr" scope="request" parameter="method" //--------添加此行------------type="com.yaung.struts.action.UsrAction" /></action-mappings> 页面中的代码
<html:form action="/usr?method=login" method="post">password : <html:password property="password" /><br />username : <html:text property="username" /><br /><html:submit /></html:form>
3.扩展LookupDispatchAction,实现不同的提交方式
页面代码如下
<html:form action="/usr" method="post">password : <html:password property="password" /><br />username : <html:text property="username" /><br /><html:submit property="prop" key="usr.login" /><html:submit property="prop" key="usr.reg" /></html:form> 资源文件中的配置
usr.login=loginusr.reg=register action-mapping中的配置
<action-mappings><action attribute="usrForm" input="/usr.jsp" name="usrForm"path="/usr" scope="request" parameter="prop" //------------添加此行----------type="com.yaung.struts.action.UsrAction" /></action-mappings> Action中的代码
public class UsrAction extends LookupDispatchAction {@Overrideprotected Map getKeyMethodMap() {Map map = new HashMap();map.put("usr.login", "login");map.put("usr.reg", "register");return map;}public ActionForward login(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {UsrForm usrForm = (UsrForm) form;// TODO Auto-generated method stubSystem.out.println("login...");return new ActionForward("/index.jsp");}public ActionForward register(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {UsrForm usrForm = (UsrForm) form;// TODO Auto-generated method stubSystem.out.println("register...");return new ActionForward("/index.jsp");}}
4.使用MappingDispatchAction
5.使用SwitchAction
6.使用ForwardAction
7.使用IncludeAction
页:
[1]