public class TextForm extends ActionForm{
String param1;
String param2;
public String getParam1() {
return param1;
}
public void setParam1(String param1) {
this.param1 = param1;
}
public String getParam2() {
return param2;
}
public void setParam2(String param2) {
this.param2 = param2;
}
public class TextAction extends Action{
private final static Logger log =Logger.getLogger(TextAction.class);
private final static String FORWARD="foward";
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
TextForm tForm=(TextForm) form;
String p1=tForm.getParam1();
String p2=tForm.getParam2();
log.debug("the value p1=" + p1);
log.debug("the value p2=" + p2);
String r1=request.getParameter("param1");
String r2=request.getParameter("param2");
log.debug("the value r1=" + r1);
log.debug("the value r2=" + r2);
return mapping.findForward(FORWARD);
}
}
<form name="textForm" method="post" action="textAction.do">
<table>
<tr>
<td>forward</td>
<td></td>
</tr>
<tr>
<td><input type="text" name="param1"></td>
<td><input type="text" name="param2"></td>
</tr>
<tr>
<td><input type="submit" value="sub"></td>
<td><input type="reset" value="rest"></td>
</tr>
</table>
</form>
在表单中输入w1和w2。从form中取和从request中取结果是一样的。因为在配置文件 中定义action中 scope="request"
同样定义为scope="session" 和从session中取的结果一样。
[2009-05-05 16:00:48,828]-DEBUG (TextAction.java:33)|the value p1=w1
[2009-05-05 16:00:48,828]-DEBUG (TextAction.java:34)|the value p2=w2
[2009-05-05 16:00:48,828]-DEBUG (TextAction.java:39)|the value r1=w1
[2009-05-05 16:00:48,828]-DEBUG (TextAction.java:40)|the value r2=w2