2011-06-28 8 views
0

JSPで次のコードを使用してログインIDとパスワードを取得しようとしました。なんらかの理由で、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> 

答えて

0

ウェルカムJSPのjsp:setPropertyタグが欠落している可能性があります(これはあなたが投稿したものです)。

+0

ありがとう、あなたは正しいです。あなたの提案されたコードがそれはうまくいきます変更... – Arvind

関連する問題