This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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
Posts: 24203
43
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
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
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!