<%@ page contentType="text/html; charset=gb2312" language="java" %> <!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> <%@ page import="java.util.*,java.sql.*,java.util.Date,chat.*,java.util.Vector"%> <jsp:useBean id="sql" scope="page" class="chat.sqlBean"></jsp:useBean> <%
String pass="";boolean boolCanLogin=true;String usernames=""; String username=request.getParameter("username"); String password=request.getParameter("password"); try{ ResultSet rs=sql.executeQuery("jdbc:odbc:user_info","select * from user_info where username=('"+username+"')"); if(rs.next()) { pass=rs.getString("password"); }
}catch(Exception ex){} %>
<%
if(pass.equals(password)) { usernames=request.getParameter("username"); usernames=new String(usernames.getBytes("ISO8859_1"),"gb2312"); String tempuser=""; Vector temp=(Vector)(getServletContext().getAttribute("chat1User")); for(int i=0;i<temp.size();i++) //temp.size()有问题 可是我不知哪里错了 把他换做10 就能通过 { // tempuser=(String)temp.elementAt(i);//如果上面没问题 加上这句就有问题了 不只为什么 难道temp的对象不能调用vector类方法 if(tempuser.equals(usernames)) { //boolCanLogin=false; } }
if(boolCanLogin==true) { //temp.addElement(username); getServletContext().setAttribute("chat1User",temp); session.putValue("username",username); Vector chatMessage=(Vector)getServletContext().getAttribute("chat1Message"); chatMessage.addElement("<font size='2' color=red>"+username+"来了["+request.getRemoteAddr()+"],欢迎光临!</font><br>"); getServletContext().setAttribute("chat1Message",chatMessage); %> <div align="center"> <p>聊天室</p> <p>欢迎聊天!</p> <p><a href="main.htm">请进...</a></p></div> <% } }else{ %> <div align="center"> <p>用户名不存在!!</p> <p><a href="init.jsp">重新申请ID</a></p></div> <% } %> <% if(boolCanLogin==true) { Hashtable lifeTime=(Hashtable)getServletContext().getAttribute("Time"); Hashtable userIP=(Hashtable)getServletContext().getAttribute("UserIP"); Date userTime=new Date(); // userIP.put((String)session.getValue("username"),request.getRemoteAddr());//如果上面的没问题 到这加上这句 问题又来了 getServletContext().setAttribute("Time",lifeTime); getServletContext().setAttribute("userIP",userIP); } %>
</body> </html>
高手们谁告诉我啊 我做的是聊天室为什么 vector对象不能用啊
错误界面是
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 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NullPointerException org.apache.jsp.chat.login_jsp._jspService(login_jsp.java:93) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.