Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

httpservlet parameter are null [duplicate]

I have a jsp page with a form. After submitting it is calling a httpservlet class. But all getParamter() operations are returning null. What am I doing wrong?

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);  

        ... 

    }
}

Edit

-I am using Tomcat v8.0

-doPost(...) method is executed, I am getting an output with System.out.println(a); which is null

like image 729
blckbird Avatar asked Nov 27 '22 06:11

blckbird


1 Answers

I have no enough reputation to put comments, so I put it as answer if you don't mind.

Please make sure that you don't call other methods on httpServletRequest before, like getReader() or getInputStream(). You can't access your post parameters after these calls.

like image 189
androberz Avatar answered Dec 04 '22 07:12

androberz