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 8462081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:04:16+00:00 2026-06-10T14:04:16+00:00

I have a servlet and JSP which share JavaBean instances – the servlet initialises

  • 0

I have a servlet and JSP which share JavaBean instances – the servlet initialises them (since the beans require constructor params) and stores them in the session, then forwards to a JSP which gets user input and submits back to the servlet via a form POST request. In the servlet’s doPost method it retrieves the JavaBeans again, but all of its values that would have been set by the form are null. If I use the GET method on the form instead then the values are populated, and whilst debugging I can see that the JavaBean property values are in fact set. So why does my doPost method retrieve beans from the session with null values? Interestingly, the fields that are passed in through constructor parameters of each object are in fact set correctly whether it’s GET or POST – it’s just those properties managed through the form that aren’t set.

Abbreviated code samples

Servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    HttpSession session = request.getSession();
    Customer customer = (Customer)session.getAttribute("customer");
    if (customer == null)
    {
        customer = new Customer(.....);
        session.setAttribute("customer", customer);
    }
    Address address = (Address)session.getAttribute("address");
    if (address == null)
    {
        address = new Address(.....);
        session.setAttribute("address", address);
    }
    forward("/checkout.jsp", request, response);
}
...
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
    PrintWriter out = response.getWriter();
    Customer customer = (Customer)request.getSession().getAttribute("customer");
    if (customer != null)
    {
        out.println("Customer: " + customer.toString());
    }
    Address address = (Address)request.getSession().getAttribute("address");
    if (address != null)
    {
        out.println("Address: " + address.toString());
    }
}

JSP

<jsp:useBean id="customer" class="com.mycompany.myproject.Customer" scope="session" />
<jsp:setProperty name="customer" property="*"/>
<jsp:useBean id="address" class="com.mycompany.myproject.Address" scope="session" />
<jsp:setProperty name="address" property="*"/>

...

<form method="POST" action="${pageContext.request.contextPath }/checkout">
    <table>
        <tr>
            <td>Title</td>
            <td><input type="text" name="title" value="${ customer.title }" /></td>
        </tr>
        <tr>
            <td>Given name</td>
            <td><input type="text" name="givenName" value="${ customer.givenName }" /></td>
        </tr>
        ...
    </table>
    <input type="submit" value="Place order" />
</form>

When I enter data into this form and click ‘Place Order’ the output of the toString() calls show all the fields of customer and address as null.

  • 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-10T14:04:18+00:00Added an answer on June 10, 2026 at 2:04 pm

    So it seems that what I wan’t isn’t possible – the <jsp:setProperty ... property="*" /> is what I need but it isn’t available until I serve up another JSP, which I want to do after accessing the bean in the servlet. So I can do one of the following:

    • Redirect to another JSP to populate my values before using the bean in my servlet
    • Set the values manually
    • Use reflection to set them (probably a winner for scalability)
    • Possibly use something like BeanUtils
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a servlet which takes us to an existing jsp, say home.jsp. This
I have one Servlet name EditEvent and one JSP which contains two forms. One
I have a JSP file Signup.jsp which submits to UserDetails servlet which inserts the
I have a JSP page which display a list from servlet, it has a
I have servlet which does a forward using requestdispatcher() to one of my jsp
I have a simple jsp/servlet application and I want to add AJAX feature to
Begining with JSP and servlet development, I have some problems with a bodyless custom
I have created a servlet that passes a string variable strname to a JSP
I have forwarded an array userName[][] from a servlet to a JSP. I can
I'm getting the following error: javax.servlet.jsp.JspException: Broken pipe Now I have seen questions/answers with

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.