request.getParameter();的意思

对于httprequrest的request.getParameter()的作用,之前我只是在用它而不知道它到底有什么作用,今天看了一遍文章突然明白了其中的意思。

   大致的内容如下:

<form action="xxxxxxx.do" >
<input name="name" value="哈哈"/>
<input type="submit" value="提交"/>
</form>
这个form提交请求后,在你的action中
String name = request.getparameter("name");
那么name的值就是“哈哈”
   它是一种取参数的方法。把jsp文件中的数据读取到出来。然后就可以封装利用起来。


再看这里:

   <body>
       <form action="${pageContext.request.contextPath }/login.action" name="frmLogin"  method="post">
          用户名: <input type="text" name="name"> <br/>
        密码: <input type="text" name="pwd"> <br/>
          <input type="submit" value="登陆"> <br/>
       </form>
  </body>
</html>

   它将jsp的内容拿出来,再封装到User实现类的setName方法中进行进一步封装。
    // 1. 获取请求数据,封装
        String name = request.getParameter("name");
        String pwd = request.getParameter("pwd");
        User user = new User();
        user.setName(name);
        user.setPwd(pwd);
---------------------
作者:IT_COOKIE_SAM
来源:CSDN
原文:https://blog.csdn.net/IT_COOKIE_SAM/article/details/52722881
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自www.cnblogs.com/GarfieldEr007/p/10235665.html
今日推荐