This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

doFilter doubt?

 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

The following piece of code is from the HFSJ book,

public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain) throws IOException, ServletException{
HttpServletRequest request = (HttpServletRequest) req;
HttpSession session = request.getSession();
Object user = session.getAttribute("user");
if (user!=null){
UserRequest ureq = new UserRequest(request, user);
chain.doFilter(ureq, response); //Line 28
}else{
RequestDispatcher rd = request.getRequestDispatcher("/login.jsp");
rd.forward(request, response);
}
}

The questions, Which is true,

Five options were give, and I'm not able to understand the explanation given for the following option,

Line 28 is invalid because request must be passed as the first argument...and they have given the reason for this option as "it is valid for a filter to wrap a request (note that UserRequest must implement ServletRequest)

I'm not able to understand the bold part. Can anyone please explain!
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can wrap the request/response object in Filter before passing it on. doFilter takes ServletRequest and ServletResponse as an argument so you will have to extend your request/response wrapper class with these interfaces in order to pass them as arguments in doFilter method.

See Servlet 2.4 Specs page 52 "Wrapping Requests and Responses"
 
Joe Harry
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali,

Can you please be a bit elaborate on this??
 
    Bookmark Topic Watch Topic
  • New Topic