请教下这是什么问题?
----访问瑞安jsp时出现错误。online.jsp
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.
<html xmlns="http://www.
<head>
<title> 用户在线信息 </title>
<meta name="website" content="http://www. />
</head>
<body>
在线用户:
<table width="400" border="1">
<%
Map<String , String> online = (Map<String , String>)application.getAttribute("online");
for (String sessionId : online.keySet())
{%>
<tr>
<td><%=sessionId%></td>
<td><%=online.get(sessionId)%></td>
</tr>
<%}%>
</table>
</body>
</html>
------错误--
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /online.jsp at line 25
22: <table width="400" border="1">
23: <%
24: Map<String , String> online = (Map<String , String>)application.getAttribute("online");
25: for (String sessionId : online.keySet())
26: {%>
27: <tr>
28: <td><%=sessionId%></td>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.NullPointerException
org.apache.jsp.online_jsp._jspService(online_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.25 logs.
----------
监听器源码:
package lee;
import java.util.Hashtable;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
@WebListener
public class OnlineListener implements HttpSessionListener{
@Override
public void sessionCreated(HttpSessionEvent se) {
HttpSession session = se.getSession();
ServletContext application = session.getServletContext();
String sessionid = session.getId();
if (session.isNew())
{
String user = (String)session.getAttribute("user");
user = (user == null) ? "游客" : user;
Map<String, String> online = (Map<String, String>)
application.getAttribute("online");
if (online == null)
{
online = new Hashtable<String, String>();
}
online.put(sessionid, user);
application.setAttribute("online", online);
}
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
HttpSession session = se.getSession();
ServletContext application = session.getServletContext();
String sessionid = session.getId();
Map<String, String> online = (Map<String, String>)
application.getAttribute("online");
if (online != null)
{
online.remove(sessionid);
}
application.setAttribute("online", online);
}
}