eclipse 在类型为“com.home.homeapp.actionform.LoginForm”的 bean 中找不到关于属性“userName”的任何信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6195908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:22:35  来源:igfitidea点击:

Cannot find any information on property 'userName' in a bean of type 'com.home.homeapp.actionform.LoginForm'

javamysqleclipseidejboss

提问by Bijoy Baral

I am using Eclipse Java EE IDE, JBOSS v5.0, java version 1.5.0_16 and MySQL v5.1.0 for my application. I am trying to Authenticate to the application using Bean and Servlet In JSP.

我的应用程序使用 Eclipse Java EE IDE、JBOSS v5.0、java 版本 1.5.0_16 和 MySQL v5.1.0。我正在尝试使用 JSP 中的 Bean 和 Servlet 对应用程序进行身份验证。

My Steps:

我的步骤:

Step:1 Create a web page "login.jsp" to login the user.

步骤:1 创建一个网页“login.jsp”来登录用户。

<html>
<head>
</head>
<body>
<form name="loginform" method="post" action="loginbean.jsp">
<br><br>
<table align="center"><tr><td><h2>Login Authentication</h2></td></tr></table>
<table width="300px" align="center" style="border:1px solid #000000;background-color:#efefef;">
<tr><td colspan=2></td></tr>
<tr><td colspan=2> </td></tr>
  <tr>
  <td><b>Login Name</b></td>
  <td><input type="text" name="userName" value=""></td>
  </tr>
  <tr>
  <td><b>Password</b></td>
  <td><input type="password" name="password" value=""></td>
  </tr>
  <tr>
  <td></td>
  <td><input type="submit" name="Submit" value="Submit"></td>
  </tr>
  <tr><td colspan=2> </td></tr>
</table>
</form>
</body>
</html>

Step:2 To create a "loginbean.jsp" to set the parameter of the login.

Step:2 创建一个“loginbean.jsp”来设置登录参数。

<%@ page language="Java" import="java.sql.*" %>  
<HTML> 
<HEAD><TITLE>DataBase Search</TITLE></HEAD>  
<BODY>
<jsp:useBean id="db" scope="request" class="logbean.LoginBean" >
  <jsp:setProperty name="db" property="userName" value="<%=request.getParameter("userName")%>"/>
  <jsp:setProperty name="db" property="password" value="<%=request.getParameter("password")%>"/>
 </jsp:useBean>
<jsp:forward page="hello">
  <jsp:param name="username" value="<%=db.getUserName()%>" />
  <jsp:param name="password" value="<%=db.getPassword()%>" />
</jsp:forward> 
</body>
</html>

Step:3 To create a "LoginBean.java" to mapping the parameter of "loginbean.jsp".

Step:3 创建一个“LoginBean.java”来映射“loginbean.jsp”的参数。

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;
  }
  }

Step:4 To create a Servlet "login.java" for validate the user login.

第4步:创建一个Servlet“login.java”来验证用户登录。

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
public class login extends HttpServlet{ 
 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException,IOException{
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  System.out.println("MySQL Connect Example.");
  Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "user_register";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"; 
  String password = "root";
 String username="";
 String userpass="";
 String strQuery= ""; 
  Statement st=null;
  ResultSet rs=null;
  HttpSession session = request.getSession(true);
  try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  if(request.getParameter("username")!=null &&
     request.getParameter("username")!="" && request.getParameter("password")!=null &&
     request.getParameter("password")!="")
  {
  username = request.getParameter("username").toString();
  userpass = request.getParameter("password").toString();
  strQuery="select * from userregister where 
    username='"+username+"' and  password='"+userpass+"'";
 System.out.println(strQuery);
  st = conn.createStatement();
  rs = st.executeQuery(strQuery);
  int count=0;
  while(rs.next())
  {
  session.setAttribute("username",rs.getString(2));
  count++;
  }
  if(count>0)
  {
  response.sendRedirect("welcome.jsp");
  }
  else
  {
 response.sendRedirect("login.jsp");
  }
  }
  else
  {
 response.sendRedirect("login.jsp");
  }
  System.out.println("Connected to the database"); 
  conn.close();
  System.out.println("Disconnected from database");
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
}

Step :5 To create the webpage "welcome.jsp" to display the message after successful message.

步骤 :5 创建网页“welcome.jsp”以显示成功消息后的消息。

<HTML> 
<HEAD><TITLE>Welcome</TITLE></HEAD>  
<BODY>
<br><br><br><br>
<table align="center" style="border:1px solid #000000;">
<%
if(session.getAttribute("username")!=null && session.getAttribute("username")!="")
{
String user = session.getAttribute("username").toString();
%>
<tr><td align="center"><h1>Welcome <b><%= user%></b></h1></td></tr>
<%
}
%>
</table>
</body>
<html>

BUT WHILE RUNNING THE APPLICATION FOLLOWING ERROR IS COMING:

但是在运行应用程序时出现以下错误:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: org.apache.jasper.JasperException: Cannot find any information on property 'userName' in a bean of type 'com.home.homeapp.actionform.LoginForm'
    org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(JspRuntimeLibrary.java:667)
    org.apache.jsp.loginbean_jsp._jspService(loginbean_jsp.java:66)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

root cause

org.apache.jasper.JasperException: Cannot find any information on property 'userName' in a bean of type 'com.home.homeapp.actionform.LoginForm'
    org.apache.jasper.runtime.JspRuntimeLibrary.getWriteMethod(JspRuntimeLibrary.java:795)
    org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(JspRuntimeLibrary.java:664)
    org.apache.jsp.loginbean_jsp._jspService(loginbean_jsp.java:66)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

note The full stack trace of the root cause is available in the JBoss Web/2.1.3.GA logs.

note 根本原因的完整堆栈跟踪可在 JBoss Web/2.1.3.GA 日志中找到。

PLEASE HELP ME OUT.

请帮帮我。

Regards Bijoy

问候 Bijoy

回答by Ricardo

Cannot find any information on property 'userName' in a bean 
of type 'com.home.homeapp.actionform.LoginForm'

It looks more like a problem with your JSPs. Bean property names begin with lowercase letters (unless you expend considerable effort to make it otherwise). It is potentially confusing that the initial lowercase letter by convention appears uppercase in getter and setter names; for example, getEmpName()and setEmpName(String)would be the getter and setter for property "empName".

它看起来更像是您的 JSP 的问题。Bean 属性名称以小写字母开头(除非您花费相当大的努力使之不如此)。按照惯例,首字母小写字母在 getter 和 setter 名称中出现大写可能会造成混淆;例如,getEmpName()andsetEmpName(String)将是 property 的 getter 和 setter "empName"

If Jasper couldn't find the bean class then it would have said so; if it goes so far as to check the presence of a particular property then it has already introspected the bean class.

如果 Jasper 找不到 bean 类,那么它会这样说;如果它甚至检查特定属性的存在,那么它已经内省了 bean 类。

Doesnt matter if you created your properties in uppercase, but I recommend you that you have to makesure that property is in lower case.

如果您以大写形式创建属性并不重要,但我建议您必须确保该属性为小写。

public String getShipmentHeaderID() {
        return ShipmentHeaderID;
    }

    public void setShipmentHeaderID(String _ShipmentHeaderID) {
        ShipmentHeaderID = _ShipmentHeaderID;
    }

    public String getShipmentHeaderNumber() {
        return ShipmentHeaderNumber;
    }

    public void setShipmentHeaderNumber(String _ShipmentHeaderNumber) {
        ShipmentHeaderNumber = _ShipmentHeaderNumber;
    }


<td width="20%"><jsp:getProperty name="pBean" property="shipmentHeaderID" /></td>

<td width="20%"><jsp:getProperty name="pBean" property="shipmentHeaderNumber" /></td>