Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Servlet doPost() returning null from Postman

I am doing a simple Java Servlet POST request without using any HTML and only using Postman. And the response from getParameter() is always null.

Here is the servlet:

@WebServlet("/api/form")
public class FormServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String orderNumber = req.getParameter("testString");
        System.out.println(orderNumber);
        resp.getWriter().print(orderNumber);
    }
}

And a picture with responses and how I am doing it:

enter image description here

EDIT

As was commented by Mukesh Verma.

All I had to do was add @MultipartConfig Annotation and I got the data.

like image 327
Richard Avatar asked Dec 31 '25 21:12

Richard


1 Answers

This is not how method getParameter works. As stated in this question, you should call the servlet with the following URL:

http://localhost:8080/api/form?testString=test
like image 125
Lorelorelore Avatar answered Jan 03 '26 12:01

Lorelorelore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!