数码产品

java学习笔记2

Cannot find any information on property '_name' in a bean of type 'com.user.

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ page language="java" import="com.user.codercrazer.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'show.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
    <jsp:useBean id="user1" class="com.user.codercrazer.User"/>
    <jsp:setProperty name="user1"  property="name" param="_name"/>
    <jsp:setProperty name="user1"  property="sex" param="_sex"/>
    <jsp:setProperty name="user1"  property="tel" param="_tel"/>
    <jsp:setProperty name="user1"  property="mail" param="_mail"/>
    
    <table>
    <tr>
    <td>姓名</td>
    <td><jsp:getProperty name="user1"  property="name"/></td>
    </tr>
    <tr>
    <td>性别</td>
    <td><jsp:getProperty name="user1"  property="sex"/></td>
    </tr>
    <tr>
    <td>电话</td>
    <td><jsp:getProperty name="user1"  property="tel"/></td>
    </tr>
    <tr>
    <td>邮件</td>
    <td><jsp:getProperty name="user1"  property="mail"/></td>
    </tr>
    </table>
    <hr/>
    <%
     User user =(User)pageContext.getAttribute("user1");
     out.println(user.getName()+user.getTel());
     %>
  </body>
</html>
<jsp:useBean id="user1" class="com.user.codercrazer.User"/>
    <jsp:setProperty name="user1"  property="name" param="_name"/>
    <jsp:setProperty name="user1"  property="sex" param="_sex"/>
    <jsp:setProperty name="user1"  property="tel" param="_tel"/>
    <jsp:setProperty name="user1"  property="mail" param="_mail"/>
中的property的参数必须与该类中的setter和getter后面的名称要一致。不一致就出现Cannot find any information on property '_name' in a bean of type 'com.user.
出错之前的代码是
    <jsp:useBean id="user1" class="com.user.codercrazer.User"/>
    <jsp:setProperty name="user1"  property="_name" param="_name"/>
    <jsp:setProperty name="user1"  property="_sex" param="_sex"/>
    <jsp:setProperty name="user1"  property="_tel" param="_tel"/>
    <jsp:setProperty name="user1"  property="_mail" param="_mail"/>
后来才发现<jsp:setProperty name="user1" property="_name" param="_name"/>的意思是user1.setName(_name)的意思,后来就想我这里是不是多了一个下划线呢,当时我把它理解为那个User类中的
变量名称,后来才仔细读了一遍,发现这里面的参数代表的意思不一样。param="_name"代表的意思是<%= request.parameter("_name")%>。
通过这次错误终于明白了java中的Usebean的应用。
posted @ 2014-06-10 00:49  Hackerman  阅读(239)  评论(0编辑  收藏  举报
数码产品