进入 jsp_test 目录，在该目录建立 forwar.jsp，pageone.jsp 和 pagetwo.jsp 文件。

forward.jsp:

<%@ page contentType="text/html;charset=gb2312"%>

<html>

<%

double freeMem = Runtime.getRuntime().freeMemory();

double totlMem = Runtime.getRuntime().totalMemory();

double percent = freeMem/totlMem;

if (percent < 0.5) {

%>

<jsp:forward page="pageone.jsp"/>

<%}else{ %>

<jsp:forward page="pagetwo.jsp"/>

<% } %>

</html>

pageone.jsp:

<%@ page contentType="text/html;charset=gb2312"%>

<html>

<body bgcolor="white">

<font color="red">

已用Java 虚拟机内存< 50%.

</html>

pagetwo.jsp:

<%@ page contentType="text/html;charset=gb2312"%>

<html>

<body bgcolor="white">

<font color="red">

已用Java 虚拟机内存> 50%.

</html>

·在浏览器上打开下面连接

http://localhost:8080/jsp_test/forward.jsp