File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher not working properly in Websphere

 
Shrikant Kulkarni
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a JSP page, in this page i am using RequestDispacher to forward the request to a servlet.
The is as below
RequestDispatcher d=application.getRequestDispatcher("/EnlargeImage");
d.forward(request, response);

In the above code "/EnlargeImage" is the URL pattern for the servlet mapping mentioned in the web.xml.

The request is forwarded to the servlet successfully. But when i try to get parameters from the request, i get null values.

Can any one tell me what is the problem and how to solve it.
[ June 01, 2006: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the request parameters weren't null before you forwarded?
[ May 31, 2006: Message edited by: Ben Souther ]
 
Shrikant Kulkarni
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes they are not null, i checked it.
 
Harpreet Hira
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i try to get parameters from the request, i get null values.

Are you looking for the parameters that originally came in the request OR are you looking for the attributes that your forwarding servlet might have set in request.

In case, you are looking for attribute then you need to use
request.getAttribute(String attributeName);

If you are looking for parameter there seems to be no reason why you shouldn't get it since it is same request object that has been passed to the forwarded servlet.
 
vishwanath nadimpally
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shrikant Kulkarni:
Hi,

I have a JSP page, in this page i am using RequestDispacher to forward the request to a servlet.
The is as below
RequestDispatcher d=application.getRequestDispatcher("/EnlargeImage");
d.forward(request, response);

In the above code "/EnlargeImage" is the URL pattern for the servlet mapping mentioned in the web.xml.

The request is forwarded to the servlet successfully. But when i try to get parameters from the request, i get null values.

Can any one tell me what is the problem and how to solve it.


Instead of this

try this

I don't know how this is different from the way you are doing it, but I think this may work.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vishwanath nadimpally:

I don't know how this is different from the way you are doing it, but I think this may work.


It isn't any different. It performs the exact same opreation.
 
Michael Valentino
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're trying to get the original parameters passed in to the servlet from the Request object, you won't be able to do so once the request has been forwarded. At this point, you should use attributes to allow the forwarded page/servlet to access those original parameters. I never really liked that, but in my experience with WebSphere implementations, that's how it worked and there's nothing I could do about it.
 
Shrikant Kulkarni
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,
The issue got solved by using
request.setAttribure("<name>",object);
in JSP and getting that request attribute from JSP by using
String name = (String)request.getAttribure("<name>");
in the forwarded servlet.
 
Ed Ward
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know you said you got this to work by setting a request scoped attribute but I thought I'd throw in an additional two cents to up my post count.
Mr Valentino is correct, the original parameters in a request are not directly available from the request once it has been forwarded.
However, why couldn't you just set the parameters to be forwarded with the request when you get the RequestDispatcher?

Something like:


Or some such thing.....



doh!
I should think about things longer before actually posting?
Bear has corrected me below yet again.
Another try:
The parameters of the original request are available, however any new parameters passed using the RequestDispatcher take precedence over parms of the original request with the same name. This means that a call to request.getParameterValues("parmName") from the included or forwarded to resource will show them at the begining of the returned String array.
Correct?
[ June 01, 2006: Message edited by: Ed Ward ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ed Ward:

Mr Valentino is correct, the original parameters in a request are not directly available from the request once it has been forwarded.


Please be aware that if this is behavior exhibited by Websphere, it is an example of specification non-compliance. In a forward, the original request is forwarded to the next resource, be it another servlet or a JSP page, and the request parameters should still be available.
[ June 01, 2006: Message edited by: Bear Bibeault ]
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Anyway, Shrikant solved his problem (was it one?) with

which is the happy end.
 
Michael Valentino
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll be the first to admit that WebSphere's implementation is FAR from perfect. Unfortunately we, the developers, don't have much of a say on what to use. But whether or not the parameters are actually passed in the WebSphere implementation i was using, one thing was clear... they weren't accessible by req.getParameter("myParam")... from the sound of the problem that started this thread, it doesn't sound like WebSphere is the only implementation this occurs in either...

P.S. Congrats, glad the getAttribute() approach worked better for you.
[ June 01, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The OP didn't say what container he was using, but it was certainly not one of Tomcat or Resin which implement this correctly.

The OP should clarify what container was being used so others can be apprised of the problem. For now I'll assume it's Websphere and move this to that forum.
[ June 01, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone else that uses Websphere corrorborate this problem?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was a hard catch, but it was actually written in the thread's topic :
"RequestDispatcher not working properly in Websphere"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I added the "in Websphere" to the topic while is was still in the Servlets forum so that other readers would not get confused and think that this was a problem with all containers.

So we're still waiting for container info from the original poster (please include version numbers too).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic