JSP学习例程系列1--forward

<jsp:forward> 重定向一个html文件,jsp文件,或者是一个程序段;

------------------------------------------------------------
//forward.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>forard demo</title>
</head>
<body>
<%
   double freeMem = Runtime.getRuntime().freeMemory();
   double totalMem = Runtime.getRuntime().totalMemory();
   double percent = freeMem/totalMem;
   if(percent < 0.5){
%>
<jsp:forward page="one.jsp"></jsp:forward>
<% } else { %>
<jsp:forward page="two.html"></jsp:forward>
<%} %>
</body>
</html>
---------------------------------------------------------------------
//one.jsp
<%@ page language="java" contentType="text/html"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>one page</title>
</head>
<body bgcolor="white">
<font color="red">
   Java VM is < 50%;
</font>

</body>
</html>
----------------------------------------------------------------------
//two.html
<html>
<head>
<title>one page</title>
</head>
<body bgcolor="white">
<font color="red">
   Java VM is > 50%;
</font>

</body>
</html>

你可能感兴趣的:(java,html,jsp)