日期:2014-05-17  浏览次数:20869 次

javabean 方法未定义
这几天在学习jsp中遇到一个问题:
一个Javabean文件(NameHandler.java),两个jsp文件(hellouser.jsp和response.jsp),其中NameHandler.java用来传递数据,hellouser.jsp文件用来让客户通过HTML表单向jsp引擎输入数据,response.jsp文件在浏览器上返回结果。
NameHandler.java代码,其中变量userhid、方法setUserhid()和getUserhid自己添加的。
Java code

package ch07;
public class NameHandler 
{
    private String username;
    private String userhid;
    public NameHandler(){
        username = null;
        userhid  = null;
    }
    public void setUsername( String name ){
        username = name;
    }
    public String getUsername() {
        return username;
    }
    public void setUserhid(Sting hid)
    {
        userhid=hid;
    }
    public String getUserhid() {
        return userhid;
    }


hellouser.jsp代码,其中标签userhid是自己后添加的。
HTML code

<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="mybean" scope="session" class="ch07.NameHandler" />
    <jsp:setProperty name="mybean" property="*" />

<%
  if(request.getParameter("username")!= null )
  {
      response.sendRedirect("response.jsp"); 
  }
%>
<html>
<head>
    <title>Hello, User</title>
</head>
<body>

<h2>Hello,my name is 柳永坡. What's yours?</h2>

<form method="post" action="hellouser.jsp">
<input type="text" name="username" size="25">
<input type="text" name="userhid" size="25"><br>
<input type="submit" value="提交">
<input type="reset" value="重置">

</form>

</body>
</html>


response.jsp代码,其中标签h2的内容是自己添加。
HTML code

<jsp:useBean id="mybean" scope="session" class="ch07.NameHandler" />
<html>
<head>
    <title>Hello, <%=mybean.getUsername()%></title>
</head>
<body>

<h1>Hello, <jsp:getProperty name="mybean" property="username" />
</h1>
<h2> hid= <%=mybean.getUserhid()%>
</h2>
</body>
</html>


运行到response.jsp页面会出现错误:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 10 in the jsp file: /response.jsp
The method getUserhid() is undefined for the type NameHandler
7: 
8: <h1>Hello, <jsp:getProperty name="mybean" property="username" />
9: </h1>
10: <h2> hid= <%=mybean.getUserhid()%>
11: </h2>
12: </body>
13: </html>


希望高手为我解释一下,谢谢!

------解决方案--------------------
先debug 不行 重新编译 重新部署
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html