aspose file tools*
The moose likes JSP and the fly likes Get  values from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Get  values from a servlet" Watch "Get  values from a servlet" New topic
Author

Get values from a servlet

Sam Maivia
Greenhorn

Joined: Jan 22, 2004
Posts: 2
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

Joined: Mar 19, 2002
Posts: 405
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

Joined: Feb 03, 2003
Posts: 205
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);


If you want to become a rich, do not work for others but make others to work for you.
Pravin Panicker
Ranch Hand

Joined: Oct 05, 2000
Posts: 62
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 R Panicker<br />SCJP,SCWCD
Pravin Panicker
Ranch Hand

Joined: Oct 05, 2000
Posts: 62

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....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get values from a servlet
 
Similar Threads
Can we use getServletConfig is JSP as we use in Servlet
problem using generics jdk1.5 in jsp
Servlet Initialization using JSP
getting initialisation parameters in JSP
web.xml parameters?