input.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<font size="5">
<form action="output.jsp" method="post">
请输入一个整数:<input type="text" name="data">
<input type="submit" value="判断">
</form>
</font>
</body>
</html>
output.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String data1=request.getParameter("data");
try{
int data2=Integer.parseInt(data1);//转换类型
if(data2%2==0){
%>
<%=data2 %> 是一个偶数。
<%
}else{
%>
<%=data2 %> 是一个奇数。
<%
}
}catch(NumberFormatException e){
%>
输入的不是整型数据,不能进行相关判断。
<%
}
%>
</body>
</html>
这是文件所在位置
- 添加到tomcat服务器上
- 运行服务器
- 在浏览器上输入http://127.0.0.1:8080/demo1111/input.jsp