File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Doubt in setAttribute() for Request object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Doubt in setAttribute() for Request object" Watch "Doubt in setAttribute() for Request object" New topic
Author

Doubt in setAttribute() for Request object

Abhijit Das
Ranch Hand

Joined: Sep 25, 2007
Posts: 156
hi,
I want to pass information from Servlet1 to Servlet2 in the request object by using setAttribute(). The hyperlink is used to invoke the Servlet2 .
I tried the following code...
Servlet1.java

Servlet2.java


For the above code, the value is coming null. Again, if i use the RequestDispatcher object in the Servlet1.java, I am getting the value.

Why ?


Abhijit Das
SCJP 5.0 | SCWCD 1.5
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Abhijit Das:
hi,
I want to pass information from Servlet1 to Servlet2 in the request object by using setAttribute(). The hyperlink is used to invoke the Servlet2 .
I tried the following code...
Servlet1.java

Servlet2.java


For the above code, the value is coming null. Again, if i use the RequestDispatcher object in the Servlet1.java, I am getting the value.

Why ?


1.if you use hyperlink to access servlet2..then you have to use session object insteadof request.

2.still if you want to use request...then forward your request object to servlet2 using RquestDispatcher

3. if you do not want to leave hperlink then pass the value (Querystring)[href="a.jsp?param=value"]

Hope This Helps
Abhijit Das
Ranch Hand

Joined: Sep 25, 2007
Posts: 156
hello friend,
I used both setAttribute() and getAttribute() in Session and ServletContext APIs with hyperlink.. It is working fine.
But without using RequestDispatcher , Is it possible to use setAttribute() in request object?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Abhijit Das:
hello friend,
I used both setAttribute() and getAttribute() in Session and ServletContext APIs with hyperlink.. It is working fine.
But without using RequestDispatcher , Is it possible to use setAttribute() in request object?

But without using RequestDispatcher --- Not Possible

Hi Abhijit Das,

request scope: imagine,if you want to access the request scope in a.jsp,
then you should forward the rquest object to a.jsp

for more Details,please read about scope of the request
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in setAttribute() for Request object