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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:24:33+00:00 2026-06-09T14:24:33+00:00

I have a jsp page (says , MyJspPage.jsp ) – <html> <head> <meta http-equiv=Content-Type

  • 0

I have a jsp page (says , MyJspPage.jsp) –

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%
    ArrayList<Person> ownerList = (ArrayList<Person>) request
            .getAttribute("ownerList");
    //set again ..
        request.setAttribute("ownerList",ownerList) ;   

%>
</head>
<body>
        <%
            //itr on all the persons ..;
            for (Person person : ownerList) {
        %>
                    // some HTML code.. 
        <%
            }
        %>
            <form action="servlet123" method="POST">
                   // some fields .. 
                   <input type="submit" value="join" />
    </form>

</body>
</html>

And a servlet –

@WebServlet("/servlet123")
public class servlet123 extends HttpServlet {
    private static final long serialVersionUID = 1L;


    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // get the then set .. 
             ArrayList<Person> ownerList = (ArrayList<Person)request.getAttribute("ownerList"); 
        request.setAttribute("ownerList", ownerList);
             // forward to `MyJspPage.jsp`
            dispather.forward(request, response);
        }

}

Firstly another servlet forward to MyJspPage.jsp and it work fine , then there is like ping pong between MyJspPage.jsp and servlet123 . The problem is that when at the 2nd time reachs to MyJspPage.jsp it throws an exception –

type Exception report

message java.lang.NullPointerException

description The server encountered an internal error (java.lang.NullPointerException) that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

It should be noted that when I omit the for loop from MyJspPage.jsp and change it to be –

   <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <%
        ArrayList<Person> ownerList = (ArrayList<Person>) request
                .getAttribute("ownerList");
        //set again ..
            request.setAttribute("ownerList",ownerList) ;   

    %>
    </head>
    <body>
                <form action="servlet123" method="POST">
                       // some fields .. 
                       <input type="submit" value="join" />
        </form>

    </body>
    </html>

all the relation between MyJspPage.jsp and servlet123 returns work fine .

  • 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-09T14:24:34+00:00Added an answer on June 9, 2026 at 2:24 pm

    This is one approach.

    JSP Code is as follows


    Instead of setting the arraylist again in the request, you can set it in session as follows
    session.setAttribute("ownerList",ownerList) ;

    You can check for the arraylist to be NOT null before using it in the for loop.

            if (ownerList != null)
            {
              for (Person person : ownerList) {
        %>
                    // some HTML code.. 
        <%
              }
            }
        %>
    

    In the servlet you can write the code as

     HttpSession session = request.getSession(false);
     ArrayList<Person> ownerList = (ArrayList<Person)session.getAttribute("ownerList"); 
     request.setAttribute("ownerList", ownerList);
     session.setAttribute("ownerList", null); // toremove unnecessary code from the session
    

    There could be other approach also. This one is just closer to the one you chose.

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

Sidebar

Related Questions

I have jsp using struts bean tag library: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8>
Title pretty much says it all. I have a page called login.jsp: <f:view> <html>
I have jsp page under WebContent/WEB-INF/forms/login.jsp - <html> <head> <link rel=stylesheet href=/Styles/Styles/Site.css type=text/css />
I have a JSP page at an address like this: http://example.com/foo/bar/rawr/something.jsp When I output
I have a JSP page that renders a block of HTML. In normal usage,
I have a custom JSP taglib included in my JSP page which says <%@
I have jsp page and html form with button on this. How execute java
I have a jsp page. if a user enters a certain text a ajax
Have JSP page with dynamically generated HTML table with unknown number of rows. Have
I have a JSP page where there is a row of buttons in their

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.