File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Differences Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply locked New topic



Joined: Dec 01, 2005
Posts: 8
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
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
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 ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

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.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

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!

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Differences
It's not a secret anymore!