2

我将 bean 对象从 servlet 传递到 jsp 文件,并希望按如下方式使用 bean 值,但它会引发运行时错误。我究竟做错了什么?

 <%@ page import = "beans.UserInfo" %>
 <%
   UserInfo userInfo = (UserInfo)session.getAttribute("userInfo");
   String userName = userInfo.getUserName();
 %>

例外情况如下:

例外

org.apache.jasper.JasperException: java.lang.NullPointerException org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419) org .apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717 )

根本原因

java.lang.NullPointerException org.apache.jsp.Login_jsp._jspService(Login_jsp.java:60) 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:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet .service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note Apache Tomcat/6.0.28 日志中提供了根本原因的完整堆栈跟踪。

4

1 回答 1

2

您在doPost或to中的代码doGet应如下所示,您正在构建beans.UserInfo和发出forward.Dispatcher

 bean.UserInfo info=new bean.UserInfo();
 //set the bean properties
 session.setAttribute("userInfo",info);
 request.getRequestDispatcher("/your_page.jsp")
    .forward(request,response);
于 2012-09-15T04:26:05.003 回答