新建login.jsp和deal.jsp页面,要求通过login.jsp页面向deal.jsp页面提交用户名和密码,在deal.jsp中通过内置对象在页面中输出用户提交的用户名和密码。
时间: 2024-05-10 12:19:00 浏览: 17
login.jsp页面代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
</head>
<body>
<form action="deal.jsp" method="post">
<label>Username:</label>
<input type="text" name="username"><br>
<label>Password:</label>
<input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
```
deal.jsp页面代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Deal Page</title>
</head>
<body>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
%>
<p>Username: <%= username %></p>
<p>Password: <%= password %></p>
</body>
</html>
```
在login.jsp页面,我们使用了一个表单来提交用户名和密码。表单的`action`属性指向deal.jsp页面,表示提交数据后将数据传递给deal.jsp页面。表单的`method`属性指定了提交数据的方式为POST。
在deal.jsp页面,我们使用内置对象`request`的`getParameter`方法来获取提交的数据。`getParameter`方法接收一个参数,即提交数据的名称,返回该名称对应的值。在这里,我们分别获取了用户名和密码,并在页面中输出。需要注意的是,`getParameter`方法返回的是字符串类型,需要使用`<%= %>`标签将其输出到页面上。