0
我在JSP中使用了以下代碼來嘗試並檢索登錄標識和密碼。出於某種原因,當我嘗試從bean輸出用戶名值時,沒有顯示任何值...我在這裏丟失了什麼?使用bean/jsp從用戶獲取登錄信息時出錯
代碼loginbean.jsp--
<%@ page language="Java" import="java.sql.*" %>
<HTML>
<HEAD><TITLE>DataBase Search</TITLE></HEAD>
<BODY>
<jsp:useBean id="db" scope="session" class="logbean.LoginBean">
<jsp:setProperty name="db" property="*" />
</jsp:useBean>
<jsp:forward page="welcome.jsp">
<jsp:param name="userName" value="<%=db.getUsername()%>" />
<jsp:param name="password" value="<%=db.getPassword()%>" />
</jsp:forward>
</body>
</html>
代碼LoginBean.java--
package logbean;
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;
}
}
代碼login.jsp--
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Taurus SEO - SEO Inspector</title>
--now there are some blocks of text -------
---code for some static blocks of text-----
---code for some static blocks of text-----
---code for some static blocks of text-----
<form name="loginform" method="post" action="welcome.jsp">
<br><br>
<h2>Login Authentication</h2> <br/>
<p/><label>User Name: <input type="text" name="username"></label>
<p/><label>Password: <input type="password" name="password"></label>
<p/><input type="submit" value="Login">
<input type="reset">
</form>
-----some more static blocks of text------
-----some more static blocks of text------
-----some more static blocks of text------
最後,以下是代碼爲welcome.jsp--
<HTML>
<HEAD><TITLE>Welcome</TITLE></HEAD>
<BODY>
<br><br><br><br>
<table align="center" style="border:1px solid #000000;">
<jsp:useBean id="db" class="logbean.LoginBean" scope="session"/>
<h4> Just checking to see if text is being shown</h4>
<h1>Welcome <b><%= db.getUsername()%></b></h1>
</table>
</body>
</html>
謝謝,你是正確的..在你建議的代碼更改它工作正常... – Arvind