This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • 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....
 
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic