Tuesday, January 22, 2013

Servlet 3.0 ( Tidbits ) ......2

  • Difference between response.sendRedirect("path" ) & req.getRequestDispatcher("path").forward(req,resp);

In former method a fresh request will be directed to url hence loosing all req level attributes and param in the redirected page . client will be notified that req is being redirected. In later  the current req attributes and params will be preserved  & client wont be  intimated that it is being taken to another page .

  • Difference between RequestURI /URL

http://localhost:8080/myWebapp/FirstServlet/second.jsp?blogname=thevoid

reqURL = http://localhost:8080/myWebapp/FirstServlet/second.jsp ( except Qry String)
reqURI = /FirstServlet/second.jsp ( excluding context and qey string )
path info = /second.jsp ( between urlPattern for servlet  and Qry string  ) 
Qry String  =  blogname=thevoid ( after  ? )

  • Difference between req.getReader() req.getInputStream()

getReader() returens Buffered Reader  & givers character data of req body  .
getInputStream() returns ServletInputStream & gives binary Data of req body .
** body doesnt include  headers


No comments: