• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Get values from a servlet

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to a pass a value from a servlet to a jsp. I am getting null pointer exception. Error 503 Service Unavailable.
In the servlets file I send the values as:
request.setAttribute("error", "Login Failure");
request.getRequestDispatcher(address).include(request,response);
This is how is get the value in the JSP file.
<% String error = (String)request.getAttribute("error") %>
I also tried it this way:
<% String error = (String)request.getParameter("error") %>
What could be the problem ?
Sam
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sam, I think you may have it backwards.
The will include the content of the resource as apart of the ServletResponse, while the
will forward the request from a servlet to another resource.
I hope this helps.
Craig.
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sam Maivia:
I am trying to a pass a value from a servlet to a jsp. I am getting null pointer exception. Error 503 Service Unavailable.
In the servlets file I send the values as:
request.setAttribute("error", "Login Failure");
request.getRequestDispatcher(address).include(request,response);
This is how is get the value in the JSP file.
<% String error = (String)request.getAttribute("error") %>
I also tried it this way:
<% String error = (String)request.getParameter("error") %>
What could be the problem ?
Sam


Try with
request.getRequestDispatcher(address).forward(request,response);
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you want to include the jsp in this servlet.. in which case the procedure you are following is correct.
Please clarify
1. What is the "address" you are giving to requestdispatcher. If it is absolute or relative.
2. Are you changing the response header in the included jsp page?
 
Pravin Panicker
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


request.setAttribute("error", "Login Failure");
request.getRequestDispatcher(address).include(request,response);
This is how is get the value in the JSP file.
<% String error = (String)request.getAttribute("error") %>
I also tried it this way:
<% String error = (String)request.getParameter("error") %>


try this rather..
<jsp:include page="address" >
<jsp aram name="error" value="Login Failure"/>
</jsp:include>
use get parameter from the jsp....
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic