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