编写两个JSP页面inputString.jsp和computer.jsp,用户可以使用inputString.jsp提供的表单输入一个字符串,并停交给computer.jsp页面,该页面通过内置对象获取inputString.jsp页面提交的字符串,并且是该字符串的长度
时间: 2024-05-13 19:14:03 浏览: 122
下面是inputString.jsp页面的代码:
```jsp
<html>
<head>
<title>输入字符串</title>
</head>
<body>
<h1>请输入一个字符串:</h1>
<form action="computer.jsp" method="post">
<input type="text" name="inputString">
<input type="submit" value="提交">
</form>
</body>
</html>
```
该页面中提供了一个表单,用户可以在文本框中输入一个字符串,并通过提交按钮将其发送给computer.jsp页面。
下面是computer.jsp页面的代码:
```jsp
<%@ page language="java" %>
<html>
<head>
<title>计算字符串长度</title>
</head>
<body>
<%
String inputString = request.getParameter("inputString");
int length = inputString.length();
%>
<h1>您输入的字符串是: <%= inputString %> </h1>
<h1>该字符串的长度是: <%= length %> </h1>
</body>
</html>
```
该页面通过内置对象request获取inputString.jsp页面提交的字符串,然后通过调用字符串的length()方法计算出字符串的长度,并将结果显示在页面上。注意,在JSP页面中,可以使用<% %>标记来插入Java代码,其中<%= %>标记用于输出表达式的值。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)