简体   繁体   中英

Not able to access request parameters in java servlets

I am using same dpPost method for two different form data. I am not able to access request parameters for second form.

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

   if("schema".equals(session.getAttribute("which"))) {
             second_html();
             //call second page here
             }

             String btnClicked= request.getParameter("p2"); // This is getting null after submitting second_html()
       if("edit".equals(session.getAttribute("which"))){
     /*   process second page here after Submit on the second page
                   I am trying to access request.getParameter() but value is null                  here for the fields in the second page       */
                 second_html();
    }
   }
  first_html() {
   // have form and submit button
   session.setAttribute("which","schema");

}
second_html() {
 // have form and submit button
  <input type='text' name='p2' id='p2' size='3' >
 session.setAttribute("which","edit");
}

EDIT : My session getters are working fine. But the request.getParameter is not working.

You are accessing session variables, not your request parameters.

You can access them using

request.getParameter("which")

If I understand your question, you should be using ServletRequest.getParameter(String) ,

String v = request.getParameter("which");
if (v.equals("schema")) {

} else if (v.equals("edit")) {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM