• Post Reply Bookmark Topic Watch Topic
  • New Topic

A query about Servlet Filter

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I am having a question with respect to Servlet Filters .I am working on already existing project which needs some changes .

In our Application , we have a Servlet Filter with this code:


And in web.xml it is configured as :



In its doFilter method it is doing only request.setCharacterEncoding("UTF8");

Can anybody please let me what this code is doing actually ??whether it is setting the request character type or it is filtering the requests ??

Please share your ideas on this .
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul

As per the sun it says that

"Overrides the name of the character encoding used in the body of this request. This method must be called prior to reading request parameters or reading input using getReader()"

So you mean to say that in our case we are not actually Filtering the requests , but actually making the character set to UTF8 format ??

Waiitng for your reply . Thanks
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:

So you mean to say that in our case we are not actually Filtering the requests , but actually making the character set to UTF8 format ??




I think you have got a wrong meaning of servlet filters. A Filter may perform any kind of task during a request response cycle.

From what you have been asking, it appears that you are expecting a Filter to block requests to certain resources.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what you have been asking, it appears that you are expecting a Filter to block requests to certain resources.


To be frank yes .

But thanks a lot for making it clear now .
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be nervous about a filter like this that blindly sets the request encoding.
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Ravi Kiran V

What this filter is doing is very obvious thing but why is it doing this is not clear.
You should find out why it is setting the encoding
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:I'd be nervous about a filter like this that blindly sets the request encoding.


:mrgreen: :D
Ours is a banking Application and we deal with Transactions data that should be in a UTF-8 so that we could be able to read data according to UTF8 format only .
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, but if it's not being *sent* in UTF-8 then simply changing the requests header doesn't *make* it be in UTF-8.

Personally, I'd try sending in something else (if that's even possible) and see what happens; pick a weird encoding.
 
Alpesh Padra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are the few Servlet Filter Essentials.

Filter Essentials :

Authentication-Blocking requests based on user identity.
Logging and auditing-Tracking users of a web application.
Image conversion-Scaling maps, and so on.
Data compression-Making downloads smaller.
Localization-Targeting the request and response to a particular locale.
XSL/T transformations of XML content-Targeting web application responses to more that one type of client.
Querying the request and acting accordingly
Blocking the request and response pair from passing any further.
Modifying the request headers and data. You do this by providing a customized version of the request.
Modifying the response headers and data. You do this by providing a customized version of the response.

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