|
How to use jsp:forward tag |
|
|
The <jsp:forward> element forwards the request object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file. The lines in the source JSP file the <jsp:forward> element are not processed.
This sample code shows the use of tag. This checks the percentage of free memory and based on that opens new page using this tag.
DemoForward.jsp
<html>
<%
double freeMemory = Runtime.getRuntime().freeMemory();
double totalMemory = Runtime.getRuntime().totalMemory();
double percent = freeMemory/totalMemory;
if(percent<0.5){
%>
<jsp:forward page="one.jsp"/>
<%}else{%>
<jsp:forward page="two.html"/>
<%}%>
</html>
|
one.jsp
<html>
<body>
<font color=”red”>
VM Memory usage<50%
</html>
|
two.html
<html>
<body bgcolor= “white”>
<font color=”red”>
VM Memory usage>50%
</body>
<html>
|
Output
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.