Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ServletRequest object modified

 
Kevin Javia
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I have implemented servlet filter in my application which supports UTF-8 encoding. This filter logs the request parameters from the request.

I am having a strange problem. When I try to get any parameters from the ServletRequest object, somehow the request object is modified and the UTF-8 characters are converted into junk characters.

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
String sessionReplication="";
String temp = req.getParameter("parameterName"); // if this line is commented, it works fine
filterChain.doFilter(req, resp);
}

Can any one give some hints on this why this is happening...

Thanks,

Kevin.
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String temp = req.getParameter("parameterName"); // if this line is commented, it works fine


You yourself have pointed out the erroneous line. Now track it up to where you are supplying the "parameterName".
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

This isn't a Java language question, but rather a question on properly using the servlet APIs, so I'm going to move it to the Servlets forum where it's likely to get a more meaningful answer.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try to get any parameters from the ServletRequest object, somehow the request object is modified


Any request for a parameter causes the entire input body to be scanned and the map of input parameters to be constructed so doing that in a filter prevents the application from doing its own input parsing. Perhaps you should do the logging after the application has finished and control returns to the filter.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!