form与request

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值