问题 java.lang.NullPointerException ,麻烦找下问题。
我从网上下了个BBS ,想借用下登录代码,自己建数据库,改字段名称却不能使用,用他的表就行。
把代码贴上来,帮我看看。在网上查询了很久,说是
主要有以下几种原因:
1、使用了未初始化的变量(虽然已经声明)
2、使用了未初始化的对象(虽然已经声明)
3,使用了关键字或已存在的类名作变量对象方法或类名。
可我找不到问题在哪里!
______________________________________________________________________
<%@ page contentType= "text/html;charset=gb2312 "%>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 用户登录 </title>
</head>
<script language= "javascript ">
<!--
function check(form)
{
if (form.bbsuser.value== " ")
{
alert( "请填写用户名! ");
form.bbsuser.focus();
return false;
}
if (form.password.value== " ")
{
alert( "请填写密码! ");
form.password.focus();
return false;
}
if (form.useryz.value== " ")
{
alert( "请输入验证码! ");
form.useryz.focus();
return false;
}
return true;
}
//-->
</script>
<body leftmargin= "8 " topmargin= "0 ">
<FORM METHOD=POST ACTION= "userloginact.jsp " onSubmit= "return check(this) ">
<br>
<br>
<br>
<br>
<br>
<br>
<table width= "35% " border= "0 " align= "center " bgcolor= "#333333 " cellspacing= "1 " cellpadding= "0 ">
<tr bgcolor= "#9999cc ">
<td colspan= "2 " height= "25 ">
<div align= "center "> <font color= "#FFFFFF "> 用户登录,请先输入用户名和密码 </font> </div>
</td>
</tr>
<tr bgcolor= "#F8F8F8 " height=25>
<TD>
<div align= "right "> 用户名: </div>
</TD>
<TD>
<INPUT TYPE= "text " NAME= "bbsuser " class= "input " size= "15 ">
</TD>
</TR>
<tr bgcolor= "#F8F8F8 " height=25>
<TD>
<div align= "right "> 密 码: </div>
</TD>
<TD>
<INPUT TYPE= "password " NAME= "password " class= "input " size= "15 ">
</TD>
</TR>
<tr bgcolor= "#F8F8F8 " height=25>
<TD height= "22 ">
<div align= "right "> 验证码: </div>
</TD>
<TD>
<INPUT NAME= "useryz " TYPE= "text " class= "input " id= "useryz " size= "4 ">
<img src= "image.jsp " border=0 align= "absmiddle "> </TD>
</TR>
<tr bgcolor= "#F8F8F8 " align=center>
<TD colspan=2 height= "30 ">
<input type= "hidden " name= "act " value= "y ">
<INPUT TYPE= "submit " value= "登录 " name= " " class= "button ">
<A HREF= "register.jsp "> <FONT COLOR= "blue "> [注册新用户] </FONT> </A> </TD>
</TR>
</TABLE>
</FORM>
</body>
</html>
_________________________________________________________________
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* "%>
<%@ page import= "java.sql.* "%>
<%@ page import= "java.util.* "%>
<%@ page import= "java.util.Date "%>
<%@ page import= "java.text.* "%>
<%@ include file= "inc/conn.jsp "%>
<%
String username = new String(request.getParameter( "bbsuser ").getBytes( "iso-8859-1 "));
String pass = new String(request.getParameter( "password ").getBytes( "iso-8859-1 "));
String rand = (String)session.getAttribute( "rand ");
String useryz = request.getParameter( "useryz ");
if (rand.equals(useryz))
{
String sql= "select * from staff where uname= ' "+username+ " ' and password= ' "+pass+ " ' ";
ResultSet rs=stmt.executeQuery(sql);
//rs.next();
if (rs.next())
{
String bbsuser=rs.getString( "nickname ");
String name=rs.getString( "uname ");
String bz=rs.getString( "bbsmanager ");
String bbsadmin=rs.getString( "bbsadmin ");
String payuser=rs.getString( "payuser ");
if (rs.getString( "payuser ").equals( "3 "))
{
out.print( " <script language= 'javascript '> ");
out.print( "alert( '对不起,你的用户名被管理员封锁了! '); ");
out.print( "history.go(-1); ");
out.print( " </script> ");
out.close();
}
else
{
//Cookie c=new Cookie( "clubusername ",username);
//response.addCookie(c);
//Cookie d=new Cookie( "pass ",pass);
//response.addCookie(d);
session.setAttribute( "bbsuser ",bbsuser);
session.setAttribute( "name ",name);
session.setAttribute( "bz ",bz);
session.setAttribute( "bbsadmin ",bbsadmin);
session.setAttribute( "payuser ",payuser);
String sqlstr= "update staff set lasttime=getdate(),tili=tili+100 where clubuser_name= ' "+(String)session.getAttribute( "name ")+ " ' ";
stmt.executeUpdate(sqlstr);
out.print( " <script language= 'javascript '> ");
out.print( "window.location.href= 'main.jsp '; ");
out.print( "parent.left.document.location.reload(); ");
//out.print( "history.go(-1); ");
out.print( " </script> ");
out.close();
}
}
else
{
out.print( " <script> ");
out.print( "alert( '用户名或密码错误 '); ");
out.print( "window.location.href= 'userlogin.jsp '; ");
out.print( " </script> ");
}
stmt.close();
conn.close();
}
else
{
out.print( " <script> ");
out.print( "alert( '验证码输入有误!请核对! '); ");
out.print( "window.location.href= 'userlogin.jsp '; ");
out.print( " </script> ");
}
%>
____________________________________________________________
错误提示:
____________________________________________________________
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)
filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:122)
root cause
java.lang.NullPointerException
org.apache.jsp.crm.userloginact_jsp._jspService(userloginact_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)
filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:122)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
[解决办法]
String username = new String(request.getParameter( "bbsuser ").getBytes( "iso-8859-1 "));
String pass = new String(request.getParameter( "password ").getBytes( "iso-8859-1 "));
String rand = (String)session.getAttribute( "rand ");
String useryz = request.getParameter( "useryz ");
是不是要改成request.getAttribute( "bbsuser ").
[解决办法]
rs.getString( "payuser ").equals( "3 ");
改成 "3 ".equals(rs.getString( "payuser "));
试试
那不都告诉你了吗org.apache.jsp.crm.userloginact_jsp._jspService(userloginact_jsp.java:93)
93行,去找到userloginact_jsp.java.应该在服务器的classes下。
[解决办法]
会不会是String rand = (String)session.getAttribute( "rand ");这个值第一次时候为空
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html