首先:我的两个jsp文件的代码如下:
teststart.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<html>
<head>
<title>输入值</title>
</head>
<body>
<FORM action="test.jsp" method=post name=form>
<INPUT type="text" name="boy">
<INPUT TYPE="submit" value="确定" name="BUTTON">
</FORM>
</body>
</html>
test.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<HTML>
<head><title>结果</title></head>
<BODY>
<%!int sum=1;%>
<%
String str=request.getParameter("boy");
// 获取值
byte []b=str.getBytes("ISO-8859-1");
str=new String(b);
int n=Integer.parseInt(str);
for(int i=1;i<=n;i++)
{ sum=sum*i;
}
%>
<br>
<%=n%>的阶乘是:
<BR>
<%=sum%>
<br/>
获取按钮的名字:
<br/>
<%=request.getParameter("BUTTON")%>
</BODY>
teststart.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<html>
<head>
<title>输入值</title>
</head>
<body>
<FORM action="test.jsp" method=post name=form>
<INPUT type="text" name="boy">
<INPUT TYPE="submit" value="确定" name="BUTTON">
</FORM>
</body>
</html>
test.jsp
<%@ page contentType="text/html;charset=GB2312"%>
<HTML>
<head><title>结果</title></head>
<BODY>
<%!int sum=1;%>
<%
String str=request.getParameter("boy");
// 获取值
byte []b=str.getBytes("ISO-8859-1");
str=new String(b);
int n=Integer.parseInt(str);
for(int i=1;i<=n;i++)
{ sum=sum*i;
}
%>
<br>
<%=n%>的阶乘是:
<BR>
<%=sum%>
<br/>
获取按钮的名字:
<br/>
<%=request.getParameter("BUTTON")%>
</BODY>
</HTML>
运行结果如图: