我将 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 日志中提供了根本原因的完整堆栈跟踪。