| 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....
|
 |
 |
|
|
subject: Get values from a servlet
|
|
|