go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  jsp:include vs. jsp:forward
 
Subject: jsp:include vs. jsp:forward
Author: WebSpider
In response to: RequestDispatcher.include vs. RequestDispatcher.forward
Posted on: 09/17/2012 02:51:07 PM

<jsp:include page="servcie_B.jsp" > 
<jsp param name="name1" value="value1" /> 
<jsp pram name="name2" value="value2" /> 
</jsp:include> 


or

<jsp:forward page="service_B.jsp" flush="true" > 
<jsp param name="name1" value="value1" /> 
<jsp pram name="name2" value="value2" /> 
</jsp:forward> 


Those are counterparts of RequestDispatcher.include vs. RequestDispatcher.forward and therefore have the same implications.


 

> On 09/17/2012 02:39:34 PM WebSpider wrote:

    if(failed){

        request.setAttribute("request_attr", "request_attr_value");
        session.setAttribute("session_attr", "session_attr_value");
        request.getRequestDispatcher("service_B.jsp").include(request, response); 
        ...
        request.getRequestDispatcher("service_C.jsp").include(request, response); 

    }else{
        ...
    }


or

    if(failed){

        request.setAttribute("request_attr", "request_attr_value");
        session.setAttribute("session_attr", "session_attr_value");
        request.getRequestDispatcher("service_B.jsp").forward(request, response); 

        return;

    }else{
        ...
    }



The key difference between the two is the fact that the include method leaves the output stream open, whereas the forward method will close the output stream after it has been invoked.

With include, you can continue processing any stuff which can be put into output stream or even inject another jsp page (service_C.jsp); With forward, however, you had better stop (return;) unless the remaining task is just background stuff, otherwise, IllegalStateException would be thrown.





References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.