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 RequestDispatcher behaving strangely with encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher behaving strangely with encoding" Watch "RequestDispatcher behaving strangely with encoding" New topic
Author

RequestDispatcher behaving strangely with encoding

Rajul Konkar
Greenhorn

Joined: Nov 05, 2008
Posts: 20

Problem statement : request.getDispatcher() encodes queryString given in targeturl

Code:


now here lRequestDispatcher contains :

it gives wrong created_date in request parameter/attribute

what is the encoding done here and why & by whom ?


Thanks in advance
Rajul konkar


Only pioneer take the untraveled path

Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

Hi Rajul,

How are you getting the value of the queryString?

Frits
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

With server side forwards it is better (and easier) to bind your variable to request scope than to try to pass them around as query string parameters.

See:
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getAttribute(java.lang.String)
And:
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/http/HttpServletResponse.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rajul Konkar
Greenhorn

Joined: Nov 05, 2008
Posts: 20

Thanks for your reply Ben & Frits

Firts : getting the value of the queryString? : can be done though inspection of the RequestDispatcher object.

Ben : with server side forwards it is better (and easier).
But according to project requirements
I need to pass the target-URL as a whole String in request.getRequestDispatcher(target-URL).
so cannot individually set the required value as attribute in request.

I want to understand why the string is encoded as Shown,
What is ideal behavior of request Dispatcher.

Thanks

Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1733
    
  25

Rajul,

Do you have a problem forwarding or just with the fact that when you look at the String in the RequestDispatcher that it is encoded differently?
If you request the queryString in the target server how does it look like then?

Regards,
Frits
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You've got control characters in your string.
The ouput from this code


is:
Date: 2010\:4\:22\:12\:15\:42
Enc Date: 2010%5C%3A4%5C%3A22%5C%3A12%5C%3A15%5C%3A42
Rajul Konkar
Greenhorn

Joined: Nov 05, 2008
Posts: 20

Thanks ,

I think I understood the problem.
I cannot use \ as a escape character in the value of request attribute,

I'll need to restructure the attribute passing mechanism.

Rajul Konkar

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No, that was not the problem.

You need to URL Encode your strings before adding them to the querystring.
There are other characters in there that need to be encoded.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher behaving strangely with encoding