This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Spring and the fly likes Filter Non Ascii characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Filter Non Ascii characters" Watch "Filter Non Ascii characters" New topic

Filter Non Ascii characters

Raghu Sha
Ranch Hand

Joined: Feb 02, 2013
Posts: 122

How to filter Non Ascii characters from user input using web filter.
Please share the sample code.

K. Tsang

Joined: Sep 13, 2007
Posts: 2985

You will need to write a CharacterEncodingFilter setting the encoding to say UTF8 for the response and request. If you are not familiar with writing a filter writing javax.servlet.filter

Remember to add this Filter to your web.xml file.

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
Raghu Sha
Ranch Hand

Joined: Feb 02, 2013
Posts: 122

I am using Spring MVC, do i need to write seperate filter for filtering Non Ascii characters or spring provides implementation?
I agree. Here's the link:
subject: Filter Non Ascii characters
It's not a secret anymore!