• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Fileter issues

 
Mathew Lee
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on servlet filter example. My filter CountryStopper.java servlet code looks like





which supposed to say
'only american spanish people can view this filetert '



otherwise if locale language is something else like chinese etc it should say
'we love people who speak : chinese '

etc


The AmericaFilter.java filter looks like






I am changing within the IE, google chrome etc browser tools options to chinese etc language
Even after refreshing or rerunning servlet
but it always displays like
'only american spanish people can view this filetert '

never i could see output like

we love people who speak : chinese etc

irrespective of change in browser locale setting in IE as well as google chrome



my web.xml looks like




My goal is to see

we love people who speak : chinese etc

as well. i am bit confused about the flow.When we run the servlet it supposed to hit the filter and based on the browser local it supposed to display values from filter right. Please advise

Any ideas, suggestions, sample code, links highly appreciated.Thanks in advance
 
veda bandaru
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


# if (language!= "spansih"){
# response.getWriter().println("only american spanish people can view this filetert");
# }
# else{
# response.getWriter().println("we love people who speak :"+ request.getLocale().getCountry());
#
# }


Is the If condition correct?
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your servlet code is never executed. In your filter, you never call chain.doFilter(request, response);. So the request never reaches your servlet. Moreover I think you'll get an IllegalStateException since you are writing some response in your filter and then again in your servlet...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Furthermore, the statement:


will never do what you expect. String comparisons MUST use the equals method. When used with object references, == and related operators compare references, not contents.


This is a common beginner mistake.

Bill
 
Mathew Lee
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wonderful it worked fine now...after i changed the filter code to



through IE 6.0 where i kept default locale it showed output like

only american spanish people can view this filetert

where as in google chrome when i change the locale to some different language it showed output like



we love people who speak :US


as in attachments.

I am confused about the flow, output , filter function on how it is integrated with this servlet example in this particular scenario based on locale. Please advise



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic