编写两个JSP页面inputString.jsp和computer.jsp,用户可以使用inputString.jsp提供的表单输入一个字符串,提交给computer.jsp,该页面通过内置对象获取inputString.jsp页面提交的字符串,并显示该字符串的长度。
InputString.jsp
<%@ page contentType="text/html;charset=utf-8"%>
<HTML>
<body>
<form action="computer.jsp" method="get" name="form">
<input type="text" name="txt" />
<input type="submit" name="submit" value="提交">
</form>
</body>
</HTML>
computer.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
String str=request.getParameter("txt");
int a=str.length();
out.println(str+"的长度为"+a);
%>
</body>
</html>