Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get HTTP form data from POST payload in Java HttpServlet? [duplicate]

I try to extract the form data from an javax.servlet.http.HttpServletRequest instance. As recommended online I tried request.getParameter(String paramKey), but it did not work. request.getParameterValues(), request.getParameterNames() and request.getParameterMap() return no form data as well. What I want is a Map with form data or another method to get them.

like image 492
loresIpsos Avatar asked Aug 03 '26 04:08

loresIpsos


1 Answers

it will behave where you write the code request.getParameter(). this thing always needs to write in the doGetPost() Method of the servlet like mentioned below. refer the following example.

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException  {

     String id = req.getParameter("realname");
     String password = req.getParameter("mypassword");
}

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

    String id = req.getParameter("realname");
    String password = req.getParameter("mypassword");
}
like image 166
user3264560 Avatar answered Aug 05 '26 18:08

user3264560



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!