dcsimg
Unable to retrieve values from request.getAttribute()
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sad_Guy
Posted On:   Tuesday, November 20, 2001 08:33 AM

I had a JSP file called targetJspPage.jsp that contains the following statement within a set of tags: <% request.setAttribute("url","/myProj/targetJspPage.jsp"); %> This information is then submitted to a servlet which will use a RequestDispatcher to retrieve the the url from the request attribute that I had set just now. The statement is as follows: RequestDispatcher dispatcher = getServletContext().getRequestDispatcher((String)request.getAttribute("url")); if (dispatcher != null) dispatcher.forward(request, response); The purpose of this procedur   More>>

I had a JSP file called

targetJspPage.jsp
that contains the following statement within a set of
			
		
tags:


			<% request.setAttribute("url","/myProj/targetJspPage.jsp"); %>
		


This information is then submitted to a servlet which will use a

RequestDispatcher
to retrieve the the url from the
request
attribute that I had set just now. The statement is as follows:



			
				
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher((String)request.getAttribute("url"));
if (dispatcher != null)
dispatcher.forward(request, response);


The purpose of this procedure is to let the servlet know which JSP file it is suppose to forward the processed results. The url is always the url of the page that is calling the servlet. Eg. In this case, my JSP file is

targetJspPage.jsp
which resides in myProj folder. So, in this JSP file, the url set for the servlet will be
/myProj/targetJspPage.jsp
. But my problem now is that the
(String)request.getAttribute("url")
statement in the servlet always returns
null
. Why is that so?    <<Less

Re: Unable to retrieve values from request.getAttribute()

Posted By:   Jeff_Hubbach  
Posted On:   Tuesday, November 20, 2001 11:22 AM

The simple answer is that your request.setAttribute is setting an attribute in the request associated with the displaying of the form. When the user submits that form, the request.getAttribute is referencing a different request (the POST request of the user submitting the form).



The easy way to solve this is to replace your request.setAttribute() scriplet with



Then change your request.getAttribute("url") to request.getParameter("url").



Jeff
About | Sitemap | Contact