Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9301945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:08:39+00:00 2026-06-18T23:08:39+00:00

I have a JSP that contains a form, containing several text inputs. I can

  • 0

I have a JSP that contains a form, containing several text inputs.

I can fill the text inputs with some data.
Once I click the submit button, my servlet’s doPost method is called, as expected.
Following the PRG design pattern, I use a “sendRedirect” call at the end of the doPost method, to avoid a second submission of my form if, for instance, the user reloads the wep page.

At this point everything is OK :
The data entered in the form are displayed on screen.

But, if I press on the submit button again, I get nasty nullPointerExceptions, because the HttpServletRequest that is passed to the doPost method of my servlet does not contain anymore the data I entered on the first submit.

I don’t understand why I get this behaviour:
The form contains the data, but it does not send it the second time.

Can you explain me what is wrong in my approach ?

[EDIT] I’m trying another approach, by using session attributes
here is some of my code:

on the JSP (myJsp.jsp)

<form method="post" action="myServlet">
field: <input type="text" name="field" value="${sessionScope.bean.field}"><br>
<input type="submit" name="lastname">
</form>

on the servlet (myServlet.java)

private Bean myBean;

doPost(...){
doSthWithMyBean(myBean);
response.sendRedirect("myJsp.jsp");
}

doGet(...){
request.getSession().setAttribute("bean",myBean);
this.getServletContext()....("myJsp.jsp").forward(request, response);
//I forget the exact methods on the description above, but you see what I do : I forward the request and response to the same jsp
}

What I understand :
– when the page is loaded for the first time, the doGet method is called. So myBean is set as an attribute of the session
– when I hit submit, the doPost method is called. Since myBean has already been set as an attribute for the session, I expect to retrieve automatically the bean info (since ${sessionScope.bean.field} is in the value field of the form)

=> With this second approach, even the first form submission fails with null pointer exception, but I don’t understand why.

If I revert back to using request parameters instead of session object

value="${bean.field}

I access the parameter via request.getParameter in the doPost method.
It works for the first submission of the form, but on the second submission, even if the form is filled with the value from the first submission, there is no request parameter named “field”.

To sum up all my talking :
– when I use request parameter : why is there no request parameter named “field” on the second submission ?
– when I use session attribute : why is it null on the first form submission ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T23:08:40+00:00Added an answer on June 18, 2026 at 11:08 pm

    using #{…} EL expression works

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following form in a Struts2 JSP that contains some radio buttons.
I have a simple JSP that contains checkbox and submit button: <form action=MappingSubmit.jsp enctype=multipart/form-data
I have a jsp that contains a table with some information from db. I
I have a .jsp that contains an IFrame with a page that has some
I have a welcome page (JSP file) for my application that contains some dynamic
I have Test class and i have jsp page that contains inputs binded to
I have a jsp file that contains this code, <form id=testForm> <input type=hidden value=study--study
I have jsp page that contains <span class=requiredFieldsMessageAsterix>*</span> I use a jsp include to
I have a form JSP web page, this form contains multiple instances of the
Hello i have a JSP page that contain a form, i want to validate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.