This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes include vs forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "include vs forward" Watch "include vs forward" New topic
Author

include vs forward

pooja jain
greenhorn
Ranch Hand

Joined: Jan 12, 2005
Posts: 213
what is the difference b/w this two tag :

<jsp:include page="second.jsp" />

&

<jsp:forward page="second.jsp" />

can any body give any example .
thanks .
pooja .


:d
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
pooja,

The <jsp:forward> action enables you to forward the request to a static HTML file, a servlet, or another JSP.

<jsp:forward page="url" />

The JSP that contains the <jsp:forward> action stops processing, clears its buffer, and forwards the request to the target resource. Note that the calling JSP should not write anything to the response prior to the <jsp:forward> action.

You can also pass additional parameters to the target resource using the <jsp aram> tag.

<jsp:forward page="test.htm" >
<jsp aram name="name1" value="value1" />
<jsp aram name="name2" value="value2" />
</jsp:forward>

To "include" another resource with a JSP, you have two options: the include directive and the include action.

The include directive executes when the JSP is compiled, which parses any JSP elements in the included file for a static result that is the same for every instance of that JSP. The syntax for the include directive is <@ include file="some-filename" %>.
The include action, on the other hand, executes for each client request of the JSP, which means the file is not parsed but included in place. This provides the capability to dynamically change not only the content that you want to include, but also the output of that content. The syntax for the include action is <jsp:include page="some-filename" flush="true" />. Note that the flush attribute must always be included (in JSP 1.1) to force a flush of the buffer in the output stream.

You can also pass parameters to the included file using the same process as the <jsp:forward> action:

<jsp:include page="template.htm" flush="true" >
<jsp aram name="name1" value="value1" />
</jsp:include>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: include vs forward
 
Similar Threads
what is the use of flush in jsp:include?
jsp:include
Passing values to JSp with href
multiple forms in JSP
Can JSP use variable defined in another jsp ?