Bookmark Topic Watch Topic
  • New Topic

Differences

 
ravikanth
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
1)wat is the difference between page and pageContext attribute?
2)Differences between Context and config?
3)differences between include directive and <jsp:include> action?
Differences between senRedirect and <jsp:forward> and RequestDispatcher?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
1) 'page' refers to the actual object which represents the JSP at run time. This is in fact a servlet, specifically implementing javax.servlet.jsp.JspPage. The container generates this class from your JSP file at translation and compilation time. 'pageContext' refers to the javax.servlet.jsp.PageContext object (extends JspContext) which allows your page access to implicit objects and provides convenience methods for locating and modifying scoped attributes.

In a servlet container, "page == this" is true.

2) There are in fact two contexts in the Web container: ServletContexts, of which only one exists per application, and which provides servlets with their "view of the application", and JspContexts which provide the convenience methods for implicit objects and scoped attributes for JSPs. There is actually no programmatic connection between the two (i.e. they don't reside in the same class hierarchy). On the other hand, ServletConfig instances exist one-per-servlet, and are essentially used to give a servlet a one-off chance to initialise itself with information from the deployment descriptor. So: the ServletContext is an application resource, and the ServletConfig is locally accessible to one particular servlet.

3) The include directive includes a resource at translation time, so for example, an imported JSP will have its source code embedded into the source code of the JSP to which it is being imported. This means that changes to the source code of the included resource are not reflected in changes to the JSP into which it is being included. The <jsp:include /> standard action includes the resource dynamically at run time. Therefore, changes to the imported resource's source code will be reflected in the calling JSP at any point in time, since the resource is invoked newly for each request. Use the include directive only for resources which don't change often, as it provides a performance benefit over <jsp:include />.

4) sendRedirect(String) is used to send a redirect response, with a 3xx status code, to the client. This causes the client's browser to jump to another URL. The RequestDispatcher's forward(), on which <jsp:forward /> is based (and may even use behind the scenes), operates only within the container - it causes processing of the current request to be allocated to another component. This allows one component (typically a servlet) to do preliminary processing, and another (JSP) to render a view. A forward() is never conveyed to the world outside the container, while a sendRedirect() always is. There is nothing even remotely similar about forward() and sendRedirect()!

Hope that clears it up!
[ January 02, 2006: Message edited by: Charles Lyons ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by ravikanth:
1)wat is the difference between page and pageContext attribute?
2)Differences between Context and config?
3)differences between include directive and <jsp:include> action?
Differences between senRedirect and <jsp:forward> and RequestDispatcher?


As these are all general questions. Tutorials/Books are the best to start with. You can find answers of all your question in the Servlet/JSP Specs. or any JSP/Servlet Book.

Thanks.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
For question #3, there is an
entry in the JSP FAQ section that covers includes. The other two get asked quite often here. If you search this and the Servlets forum, you will find plent of discussion on those topics.
Or... you could do as Adeel said and pick up a book or two.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'm sorry to see that after repeated warnings, you still haven't changed your display name as requested. Your account is now closed. Bye, ravikanth!
 
    Bookmark Topic Watch Topic
  • New Topic