Using JSP forward XML Tag

The following example illustrates using <jsp:forward> tag. This tag is used to forward the current jsp page to another page (any page jsp or html). Just like redirect. But here, you can transfer the data from one jsp page to another jsp or servlet page by setting the request attributes. Here is the syntax
<jsp:forward page="sample.jsp"/>

Here page is a mandatory attribute.

Folder structure
           |_ jsp5
                 |_ index.jsp
                 |_ sample.jsp


    This is in the html body<br/>
    request.setAttribute("sample","this is sample text......");
    <jsp:forward page="sample.jsp"/>

Here, using the setAttribute() we have set an attribute to the corresponding request. The request object here is carried to the sample.jsp file because of the <jsp:forward> tag. The request here is forwarded.



Posted by at on

Tags: Java Server Pages,