Jsp:forward
Introduction:
1. The <jsp:forward> element forwards the request object from one JSP file to another file.
2. The target file can be an HTML file, another JSP file, or a servlet, forwarded files must me with in same web application.
3. As long as it is in the same application context as the forwarding JSP file. The lines in the source JSP file after the <jsp:forward> element are not processed.
<jsp: forward page= “/second.jsp” />
Note:You can pass parameter names and values to the target file by using a <jsp:param> clause. If you use <jsp:param>, the target file should be a dynamic file that can handle the parameters.
Ex: first.jsp
<h2>This is First JSP</h2> <jsp:forward page="/second.jsp"></jsp:forward> |
second.jsp
<h2> This is second JSP </h2> |
Output: http://localhost:8080/Scwcd_jsp/first.jsp
1. Forward Standard Action
<jsp: forward page= “/second.jsp>
2. By Using Page Context Implicit Object
<%
pageContext.forward (“second.jsp”);
%>
3. By Using RequestDispatcher
<%
RequestDispatcher rd=request.getRequestDispatcher (“second.jsp”);
rd.forward (req., resp);
%>
No comments:
Post a Comment