Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get values from a servlet

 
Sam Maivia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • 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.
 
himanshu patel
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • 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);
 
Pravin Panicker
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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
  • 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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic