• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can not Reflesh Page and NullPointerException Problems

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all:
I am doing one project using Java Servlet and JSP. Tomcat3.2 is my test environment.
I created a servelt (ParserServlet) to parse a XML file
to get the product's "Category" name and "Product Name".
I created an "ProductBean" object to store these info.
I put this bean object into request object
request.setAttribute("product", productBeanObject)
Then I use RequestDispatch("/WebApplication/jsp/Display.jsp").forward(request, response).
In Display.jsp, it create a "ProductBean" object and I retrieve
the object back from the request.
productBeanObject = (ProductBean)request.getAttribute("product")
then Display.jsp shows the product's Category and its name.
I start Tomcat, Open web broswer, enter:
"http://127.0.0.1:8080/WebApplication/servlet/ParserServlet"
Everything is OK. The broswer shows the product's Category and its name. The URL in the Address location of the IE5.0 remain the same as it is.
"http://127.0.0.1:8080/WebApplication/servlet/ParserServlet"
instead of changing to
"http://127.0.0.1:8080/WebApplication/jsp/Display.jsp" (Why does the URL not change after the redirection)
My problem is:
When I "reflesh" the broswer,(URL is the same as "http://127.0.0.1:8080/WebApplication/servlet/ParserServlet")
The broswer does show the same result as the first calling
"http://127.0.0.1:8080/WebApplication/servlet/ParserServlet"
However it give me error:
java.lang.NullPointerException
Can any friend tell me the reseason and how to solvet this problem (Why I can't refesh this page?) Is it the session problem or I need to use session.setAttribute() , or session.putValue() instead of using request.setAttribute()
After the "reflesh" the page, I check what is being passed into the request object. The servlet does pass the "ProductBean" Object into the request, but the value inside the object in NULL.
So it throws exception:
java.lang.NullPointerException
I have to restart TOMCAT again whenever I reflesh this page, then it show the result. It is not what we want.
Any suggestion and advice would be very appreciated.
Thank you in advanced!!
James
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James,
I think you guessed the answer right. Any object set as request.setAttribute(*** ,***) lives only for that particular request. Which means once some response comes from the server end to the client end, the object which was put in HttpRequest has gone.
If you change as session.setAttribute(***,***), the set object will live for the whole session of the user, which means it will be available for subsquent requests.
This is the reason, generally developers put the login info in session scope, so that each request from client side can be validated against, the session scoped login info object.
regds
maha anna
[This message has been edited by maha anna (edited February 05, 2001).]
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
URL doesn't change, becose you you use forward. If you want URL to be vhanged, you should use sendRedirect instead.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic