Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

filter Q from HFSJ

 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi please give relavent info for each option.


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);
} else{
RequestDispatcher rd = request.getRequestDispatcher("/login.jsp");
rd.forward(request,response);
}

What is true?

A.An exception will be thrown if "rd.forward(request,response);" line executes

B. Line "chain.doFilter(ureq,response);" is invalid bacause request must be passed the first argument

C. This line "chain.doFilter(ureq,response);" inserted somewhere in the else block

D. doFilter() method signature is incorrect

E. NOne of the above



Note UserRequest request Wrapper class
[ August 06, 2008: Message edited by: Chintu sirivennela ]
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can some one please help me.
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


May i know what is this UserRequest ? Is this extends some ServletRequest/HttpServletRequest or it just a plain java class?
 
deepa raj
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A.An exception will be thrown if "rd.forward(request,response);" line executes



B. Line "chain.doFilter(ureq,response);" is invalid bacause request must be passed the first argument



C. This line "chain.doFilter(ureq,response);" inserted somewhere in the else block


D. doFilter() method signature is incorrect




E. NOne of the above




Please correct me if i am wrong.
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi anand,
UserRequest request Wrapper class
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK.Then corect option is E. Explanation is already given above.
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks deepa raj and Anand,

I accepted the answer.
According to above explanation ->

1.Filter can forward the request to another Servlet or JSP. So what happens to the flow of filter.
2.Filter need not call chain,doFilter() method, so what ppanes to the flow of filter.

I thought We must call chain,doFilter() in filter doFilter() method.
 
deepa raj
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not must to call the FilterChain.doFilter method. I think so.

If we call the chain.doFilter means , the next filter may be called otherwise the filter process might be stopped.

i am not 100% sure. can somebody please help to confirm the filter process ?
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doFilter method main responsibility is to call either any resources in the chain or it might be used to stop the processing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic