当客户请求时,Servlet容器创建SrevletRequest对象(用于封装客户的请求信息),这个对象将被容器作为service()方法的参数之一传递给Srevlet,Servlet可以利用ServletRequest对象获取客户端请求数据。
<form action="loing.do" method="post">
<div> <span>用户名</span> <div> <input type="text" name="name" id="user" /> </div> <span>密码</span> <div> <input type="password" name="password" id="pw" /> </div> </div> <div class="button"> <input type="submit" value=" 登 录" class="submit"> </div> </form>// 取得请求的参数
String name = request.getParameter("name"); String password = request.getParameter("password");//用request传递参数
request.setAttribute("msg", "密码错误,请重新输入!");
request.setAttribute("msg", "用户" + name + "登录成功");
<body>
<c:if test="${not empty requestScope.msg}"></c:if> <h1>${requestScope.msg}</h1> 获取参数。</body>