• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpServletResponse sendRedirect

 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Please provide the explanation why the choices given cannot be considered as an answer for the question
Question:
You are calling the method HttpServletResponse.sendRedirect(String path) and you want to make sure that the user continues in the same session. How do you that?
1) By calling the method with an absolute path as the argument
2) By encoding the path with HttpServletResponse.encodeURL method
3) By encoding the path with HttpServletResponse.encodeRedirectURL method
4) If you use sendRedirect the session is lost.
Correct Answer
3) By encoding the path with HttpServletResponse.encodeRedirectURL method
Choices:
1) By calling the method with an absolute path as the argument
Explanation: False, There is no session management.
2) By encoding the path with HttpServletResponse.encodeURL method.
Explanation: ?
3) By encoding the path with HttpServletResponse.encodeRedirectURL method
Explanation: This method is used for the HttpServletResponse.sendRedirect method.
4) If you use sendRedirect the session is lost.
Explanation: ?
Thanks
-- Ravi
 
Dumitru Husleag
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cookies are not a reliable mechanism (they can be disabled in the browser). That is why URL rewriting is needed.
Now, why encodeURL is not good for sendRedirect, the answer is in the javadoc.
Quote:
"Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method.
All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.".

Question:
You are calling the method HttpServletResponse.sendRedirect(String path) and you want to make sure that the user continues in the same session. How do you that?
1) By calling the method with an absolute path as the argument
2) By encoding the path with HttpServletResponse.encodeURL method
3) By encoding the path with HttpServletResponse.encodeRedirectURL method
4) If you use sendRedirect the session is lost.
Correct Answer
3) By encoding the path with HttpServletResponse.encodeRedirectURL method
Choices:
1) By calling the method with an absolute path as the argument
Explanation: False, There is no session management.
2) By encoding the path with HttpServletResponse.encodeURL method.
Explanation: ?
3) By encoding the path with HttpServletResponse.encodeRedirectURL method
Explanation: This method is used for the HttpServletResponse.sendRedirect method.
4) If you use sendRedirect the session is lost.
Explanation: ?
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why the session is lost when HttpServletResponse.sendRedirect method is used?
-- Ravindra
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple answer for this. The encodeRidirectURL method appends a session Id representing the current session to the URL whereas the sendDirect method doesn't do that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic