12 package com.jacktan.struts.formbean; 34 import java.util.*; 5 import javax.servlet.http.*; 6 import org.apache.struts.action.*; 8 public class CustomForm extends ActionForm { 10 private Map formvalueMap = new HashMap(); 12 public void setFormvalueMap(Map p_FormvalueMap){ 14 this.formvalueMap = p_FormvalueMap; 15 } 16 public Map getFormvalueMap(){ 18 return this.formvalueMap; 19 } 20 public void setFormvalue(String key,Object value){ 22 formvalueMap.put(key,value); 23 } 24 public Object getFormvalue(String key){ 26 return formvalueMap.get(key); 27 } 28 } |
12 package com.jacktan.struts.action; 34 import java.util.*; 5 import javax.servlet.http.*; 6 import org.apache.struts.action.*; 8 import com.jacktan.struts.formbean.CustomForm 10 public class CustomAction extends Action { 12 public ActionForward execute(ActionMapping p_Mapping, 15 ActionForm p_Form, 16 HttpServletRequest p_Request, 17 HttpServletResponse p_Response) 18 throws Exception{ 21 Map formvalues =((CustomForm)p_Form).getFormvalueMap(); 23 return p_Mapping.findForward("Success"); 25 } 26 } |
<html:form action="login"> <table width="100%" border="0"> <tr> <td width="3%"> ;</td> <td width="31%"> ;</td> <td width="66%" rowspan="6" valign="top"> <html:errors/> </td> </tr> <tr> <td> ;</td> <td height="25">用户名</td> </tr> <tr> <td> ;</td> <td height="25"> <html:text property="formvalue(username)" size="12" maxlength="12"/></td> </tr> <tr> <td> ;</td> <td height="25">密码</td> </tr> <tr> <td> ;</td> <td height="25"> <html:password property="formvalue(password)" size="12" maxlength="12" redisplay="false"/> </td> </tr> <tr> <td> ;</td> <td height="25"> <html:submit value="登录"/> <html:button property="close" value="关闭" onclick="Close()"/> </td> </tr> </table> |
<form-beans> <form-bean name="CustomForm" type="com.jacktan.struts.formbean.CustomForm"/> </form-beans> |
<action path="/login" type="com.jacktan.struts.action.CustomAction" name="addDeviceForm" scope="request"> <forward name="login" path="main.jsp"/> </action> |
1 Set set = formvalues.entrySet(); 2 Iterator it = set.iterator(); 3 while( it.hasNext() ){ 4 Map.Entry me = (Map.Entry)it.next(); 5 System.out.println((String)me.getKey); 6 System.out.println((String)me.getvalue); 7 } |