好的,所以我正在尝试为我正在使用的网站创建一个登录页面。我在 Eclipse 中使用 Javabeans。我已设置我的 bean,但未设置属性。
这是我的 login.jsp 页面的代码:
<!DOCTYPE html>
<%@page import="java.util.*" %>
<html>
<head>
<title>Log-In</title>
<meta http-equiv=Content-Type content="text/html">
</head>
<body>
<jsp:useBean id="login" class="edu.iup.COSC473.Beans.LoginBean" scope="session"/>
<jsp:setProperty name="login" property="*"/>
<form method="post" action="check.jsp">
<table width="100%">
<tr>
<td>Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="text" name="password"></td>
</tr>
<tr>
<td><input type="submit"/></td>
</table>
</form>
</body>
</html>
这是 check.jsp 的代码(我正在使用的一个测试页面,用于查看正在设置的属性):
<!DOCTYPE html>
<%@page import="java.util.*" %>
<html>
<head>
<title>Log-In</title>
<meta http-equiv=Content-Type content="text/html">
</head>
<body>
<jsp:useBean id="login" class="edu.iup.COSC473.Beans.LoginBean" scope="session"/>
User Name: <jsp:getProperty name="login" property="username" />
</body>
</html>
最后,这是 LoginBean.java 类:
public class LoginBean {
String username;
String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
我希望有人能帮我弄清楚为什么当我点击登录页面上的提交按钮时我的属性没有被设置。预先感谢您的帮助!
最佳答案
在你的 check.jsp 中使用 setProperty 标签,因为参数被提交到这个页面并且只会在这个页面的 bean 中设置。
关于java - 使用 Javabeans 创建登录页面(未设置属性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28909620/