标题:请教下这是什么问题?
只看楼主
africanfarme
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-2-18
结帖率:0
 问题点数:0 回复次数:0 
请教下这是什么问题?
----访问瑞安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);
    }

}
搜索更多相关主题的帖子: html head 在线用户 content website 
2012-02-23 21:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-361486-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087070 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved