我有个页面
<form action="reg.jsp" method="post">
<table>
<tr>
<td>用户名:</td><td><input type="text" name="name" /></td>
</tr>
<tr>
<td>性别:</td><td><input type="radio" name="sex" value="1" checked="checked"/>男<input type="radio" name="sex" value="0" />女</td>
</tr>
<tr><td>学历:</td><td>
<select size="1" name="education">
<option value="" selected>......</option>
<option value="高中">高中</option>
<option value="大学">大学</option>
<option value="硕士">硕士</option>
<option value="博士">博士</option>
</select>
</td>
</tr>
<tr><td>Email:</td><td><input type="text" name="mail" /></td>
</tr>
<tr>
<td><input type="reset" value="重置"/></td>
<td><input type="submit" value="提交" /></td>
</tr>
</table>
</form>提交给reg.jsp处理reg.jsp如下
<%@ page contentType="text/html;charset=gb2312" %>
<%
request.setCharacterEncoding("gb2312");%>
<jsp:useBean id="user" scope="session" class="test.UserBean"/>
<jsp:setProperty name="user" property="*"/>
<jsp:setProperty name="user" property="email" param="mail"/>
注册成功!
<a href="userinfo.jsp">显示</a>
<a href="reg.html">返回</a>
处理是成功的可是我想显示JAVABean中的属性出错
userinfo.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<jsp.useBean id="user" scope="session" class="test.UserBean"/>
你的姓名:<jsp:getProperty name="user" property="name"/><br />
<br>
你的学历:<jsp:getProperty name="user" property="education"/>
你的E-mail:<jsp:getProperty name="user" property="email"/>
<br />我测试很多次,好像是<jsp:getProperty>出错
其中,JAVABean编写正确请大虾,帮我检查检查下面试我的JAVABean
package test;import java.io.Serializable;
public class UserBean  implements Serializable{
  private String name;
  private int sex;
  private String education;
  private String email;
  public UserBean() {
  }
  public String getName()
  {
    return name;
  }
  public void setName(String name)
  {
    this.name=name;
  }
  public int getSex()
  {
    return sex;
  }
  public void setSex(int sex)
  {
    this.sex=sex;
  }
  public String getEducation()
  {
    return education;
  }
  public void setEducation(String education)
  {
    this.education=education;
  }
  public String getEmail()
  {
    return email;
  }
  public void setEmail(String email)
  {
    this.email=email;
  }
}
下面是我的错误:
type Exception reportmessage  description The server encountered an internal error () that prevented it from fulfilling this request.exception  org.apache.jasper.JasperException: Attempted a bean operation on a null object.
org.apache.jasper.runtime.JspRuntimeLibrary.handleGetProperty(JspRuntimeLibrary.java:603)
org.apache.jsp.userinfo_jsp._jspService(userinfo_jsp.java:56)
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:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

解决方案 »

  1.   

    确定session里面有存那个对象?
      

  2.   

    建 议你删除WEB-INF/classes下在的所有目录和文件然后再把工程重新编译一次
      

  3.   

    以下是我测试用的代码:index.html:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>注册主页</title>
    </head>
    <body>
    <form action= "reg.jsp" method="get"> 
    <table> 
    <tr> 
    <td> 用户名: </td> <td> <input type= "text" name="userName" id="userName"/> </td> 
    </tr> 
    <tr> <td> 学历: </td> <td> 
    <select   size= "1"   name= "education" id="education"> 
    <option   value= ""   selected> ...... </option> 
    <option   value= "高中 "> 高中 </option> 
    <option   value= "大学 "> 大学 </option> 
    <option   value= "硕士 "> 硕士 </option> 
    <option   value= "博士 "> 博士 </option> 
    </select> 
    </td> 
    </tr> 
    <tr> <td> Email: </td> <td> <input type="text" name="email" id="email"/> </td> 
    </tr> 
    <tr> 
    <td> <input   type= "reset"   value= "重置 "/> </td> 
    <td> <input   type= "submit"   value= "提交 "   /> </td> 
    </tr> 
    </table> 
    </form> 
    </body>
    </html>2 reg.jsp:
    <%@ page language="java" contentType="text/html; charset=gb2312"
        pageEncoding="gb2312"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%
    request.setCharacterEncoding("gb2312");
    %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>注册界面</title>
    </head>
    <body>
    <jsp:useBean id= "user" scope= "session" class= "test.UserBean"/> 
    <jsp:setProperty name= "user" property= "*"/>  
    注册成功!
    <a href= "userinfo.jsp">显示 </a>
    &nbsp;&nbsp; 
    <a href= "index.html"> 返回 </a> 
    </body>
    </html>3.UserBean:
    package test;
    public class UserBean{ 
        private   String   userName; 
        private   String   education; 
        private   String   email; 
        public UserBean() { 
        } 
        public   String   getUserName() 
        { 
            return userName; 
        } 
        public   void   setUserName(String name) 
        { 
            this.userName=name; 
        } 
        public   String   getEducation() 
        { 
            return education; 
        } 
        public   void   setEducation(String   education) 
        { 
            this.education=education; 
        } 
        public   String   getEmail() 
        { 
            return email; 
        } 
        public   void   setEmail(String   email) 
        { 
            this.email=email; 
        } 
    }4.userinfo.jsp:
    <%@ page language="java" contentType="text/html; charset=gb2312"
        pageEncoding="gb2312"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <jsp:useBean   id= "user"   scope= "session"   class= "test.UserBean"/> 
    你的姓名: <jsp:getProperty   name= "user"   property= "userName"/><br/> 
    <br> 
    你的学历: <jsp:getProperty   name= "user"   property= "education"/> 
    你的E-mail: <jsp:getProperty   name= "user"   property= "email"/> 
    <br></br>遇到的问题:输出信息有时乱码,有时又正常的,当然与这个问题无关拉,呵呵。只能怪我机子破,开句玩笑。这个中文乱码问题,最好单独处理。
      

  4.   

    不好意思,写出错了
    <jsp.useBean   id= "user "   scope= "session "   class= "test.UserBean "/> 应该是
    <jsp:useBean   id= "user "   scope= "session "   class= "test.UserBean "/>