Context Object with RequestDispatcher |
Request Object With RequestDispatcher |
1. Using Context object with the getRequestDispatcher() its mandatory to write url starting with " / " . |
1. Using Request object with the getRequestDispatcher(), its not mandatory to use " / " before url.
|
2. It uses the context path of the URI.
|
2. It uses the context path if we write " / " before url and if we are not writing " / " then the request will be forwarded using relative path. |
3. If we are not writing " / " before
url then container will throw IllegalArgumentException exception " This given path is invalid, since it doesn't start with / " . |
3. If we are not writing " / " before url then it forward the request using relative path. |
4. For ex-
RequestDispatcher rd = getServletContext(). getRequestDispatcher("/url"); |
4. For ex- RequestDispatcher rd = getServletContext(). getRequestDispatcher("/url"); or RequestDispatcher rd = getServletContext(). getRequestDispatcher("url") ; |
Monday, 9 December 2013
Difference between using Context Object and Request Object with the RequestDispatcher
Tuesday, 3 December 2013
Difference between Shallow and Deep Cloning
Shallow Cloning |
Deep Cloning |
1. It is a default cloning and can be done by using clone() method. |
1.It is done by the user itself by writing the code for the deep cloning.
|
2. Shallow cloning fails to clone object members.
|
2. Using deep cloning we can able to clone object member also . |
Monday, 2 December 2013
Difference between include and forward of RequestDispatcher in Servlet
include() |
forward() |
1. It is used to include the response to the source servlet. |
1. It is used to forward the request to the other servlet or JSP page.
|
2. Response get committed after including all other resources(servlet/JSP) responses.
|
2. Response get committed by the RequestDispatcher object and also close the response stream.
|
3. A servlet class can have multiple include statement to execute.
|
3. A servlet class can have multiple forward statement conditionally but will execute only one.
|
4. After executing include() control will back to the source servlet and will add information to response object.
|
4. After executing forward() control will
back to the source servlet but other informations cannot be added to that response object. |
Subscribe to:
Posts (Atom)