httpservlet参数为null

时间:2015-04-22 07:49:39

标签: java jsp tomcat servlets

我有一个带表单的jsp页面。提交后,它正在调用httpservlet类。但是所有getParamter()操作都返回null。我做错了什么?

JSP

<form action="GatherController" method="post">
    <input type='text' name="a"/>
    <input type='date' name="b" />
    ...
    <input type="submit" />
</form>

的Servlet

@WebServlet(name = "GatherController", urlPatterns = { "/GatherController" })
public class GatherController extends HttpServlet {

    ...

    @Override
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {


        String a = request.getParameter("a");
        System.out.println(a);  

        ... 

    }
}

修改

- 我正在使用Tomcat v8.0

-doPost(...)方法已执行,我的System.out.println(a);输出为null

2 个答案:

答案 0 :(得分:1)

我没有足够的声誉来发表评论,所以如果你不介意我就把它作为答案。

请确保您之前没有在httpServletRequest上拨打其他方法,例如getReader()getInputStream()。这些电话会议后您无法访问您的帖子参数。

答案 1 :(得分:-1)

<form action="GatherController" method="post"><input type="text" name="a"/>

请使用双引号,它可能会起作用