Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Lets understand main difference between jsp:include and jsp:forward.</p> <p>jsp:include, includes the page inside the current page. So the included page will appear exactly where u have added the jsp command inside the current page.</p> <p>e.g.</p> <pre><code>... &lt;jsp:include page="inc/include.jsp" /&gt; ... </code></pre> <p>but jsp:forward will forward the current page to the forwarded page. Meaning when the current page is called the forwarded page is called immediately after.</p> <p>e.g.</p> <pre><code>if (...) { forwarded to pageOne.jsp } else if (...) { forwarded to pageTwo.jsp } </code></pre> <p>Now following is the way we can access parameters for both jsp:forward and jsp:include.</p> <p>jsp:include : we can access parameters using param not by request object. e.g.</p> <pre><code>${param.param1} </code></pre> <p>while in jsp:forward : we can access parameters using request object. e.g.</p> <pre><code>request.getParameter("param1") </code></pre> <p>This is what the main difference between the parameters in jsp:inlcude and jsp:forward. And thus, we are getting new value in jsp:forward (say Lname=xyz).</p> <p>example:</p> <p>say we have a parameter Lname=xyz in request object. In current jsp it can be accessed using below code</p> <pre><code>&lt;%= (String)request.getParameter("Lname"); %&gt; &lt;%-- This will print xyz on jsp --%&gt; </code></pre> <p>Now, further the same parameter name can be used with jsp:forward, like...</p> <pre><code>&lt;jsp:forward page="fwd/pageOne.jsp?Lname=abc" /&gt; </code></pre> <p>or</p> <pre><code>&lt;jsp:forward page="fwd/pageOne.jsp"&gt; &lt;param name="Lname" value="abc"/&gt; &lt;/jsp:forward&gt; </code></pre> <p>This will result Lname=abc in fwd/pageOne.jsp using request.getParameter() method.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload