Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

ServletRequest object modified  RSS feed

 
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.
 
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".
 
author and iconoclast
Sheriff
Posts: 24220
40
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.
 
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!