Servlet中的getParameter来自JSP中的表单

时间:2015-08-27 03:53:25

标签: forms jsp servlets

我有一个带有表单的jsp

<form action="Login" method="post">
    <h1>Login</h1>
    <div>
        <input type="text" placeholder="Email" required="" id="email" />
    </div>
    <div>
        <input type="password" placeholder="Password" required="" id="password" />
    </div>
    <div>
        <input type="submit" value="Login" />
    </div>
</form><!-- form -->

在登录Servlet中,我执行下一步:

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
    String pass = request.getParameter("password");
    String email = request.getParameter("email");

问题是传递和电子邮件始终为空,我不知道为什么。

1 个答案:

答案 0 :(得分:3)

因为您通过name获取参数。试着说:

<input type="text" placeholder="Email" required="" id="email" name="email" />

你会得到参数。