****太奇怪的问题!****我的最后30分奉上!虽有点少!但我有诚意!

yunrong 2002-05-22 04:55:22
这个程序昨天用还好使
为什么今天就有这样的错误!

表单提交的代码如下<%@ page language="java" import="java.sql.*"%>
<%@ page import ="java.util.*"%>
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>user register</title>
</head>
<body>
<%
String userid=request.getParameter("userid");
String password=request.getParameter("password");
String confirm_password=request.getParameter("confirm_password");
String question=request.getParameter("question");
String answer=request.getParameter("answer");
String name=request.getParameter("name");
String sex=request.getParameter("sex");
String literacy=request.getParameter("literacy");
String mail=request.getParameter("mail");
String aihao=request.getParameter("aihao");
byte[] tmpbyte=userid.getBytes("ISO8859_1");
userid=new String(tmpbyte);
tmpbyte=password.getBytes("ISO8859_1");
password=new String(tmpbyte);
tmpbyte=confirm_password.getBytes("ISO8859_1");
confirm_password=new String(tmpbyte);
tmpbyte=question.getBytes("ISO8859_1");
question=new String(tmpbyte);
tmpbyte=answer.getBytes("ISO8859_1");
answer=new String(tmpbyte);
tmpbyte=name.getBytes("ISO8859_1");
name=new String(tmpbyte);
tmpbyte=literacy.getBytes("ISO8859_1");
literacy=new String(tmpbyte);
tmpbyte=aihao.getBytes("ISO8859_1");
aihao=new String(tmpbyte);
%>
<%
if((userid.length()==0)||(password.length()==0)||(confirm_password.length()==0))
out.println("登录名,密码,及密码校验不能为空!");
else if ((question.length()==0)||(answer.length()==0))
out.println("密码遗失提示问题及答案不能为空!");
else if (!password.equals(confirm_password))
out.println("密码与确认密码不一致!");
else if( mail.length()==0)
out.println("E-MAIL不能为空!");
else if(mail.indexOf('@')<=0)
out.println("EMAIL 地址有错误!");
else{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:nn";
Connection con=DriverManager.getConnection(url);
PreparedStatement select_stm=con.prepareStatement("select password from nn where userid=?");
select_stm.setString(1,userid);
ResultSet result=select_stm.executeQuery();
String temp_password=null;
if(result.next())
temp_password=result.getString(1);
result.close();

if (temp_password!=null)
out.println("这个用户名已存在,请再换一个名字注册!");
else
{ String sqlstr="select *from nn";
Statement stmt=con.createStatement();
sqlstr="insert into nn(userid,password,confirm_password,question,answer,name,sex,mail,literacy,aihao) values('"+userid+"','"+password+"','"+confirm_password+"', '"+question+"','"+answer+"','"+name+"','"+sex+"','"+mail+"','"+literacy+"','"+aihao+"')";
stmt.executeUpdate(sqlstr);
stmt.close();
}

%>
<%@ include file="succeed.jsp" %>
<%
}catch (Exception e){out.println(e);}
}
%>
</body>
</html>
****************************************************************************
错误是

500 Internal Server Error
/kk/register_action.jsp:

null
java.lang.NullPointerException
at jrun__kk__register_action2ejsp17._jspService(jrun__kk__register_action2ejsp17.java:69)
at allaire.jrun.jsp.HttpJSPServlet.service(HttpJSPServlet.java:40)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java:925)
at allaire.jrun.servlet.JRunNamedDispatcher.forward(JRunNamedDispatcher.java:34)
at allaire.jrun.jsp.JSPServlet.service(JSPServlet.java:174)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java:925)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java:88)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java:1131)
at allaire.jrun.servlet.JvmContext.dispatch(JvmContext.java:330)
at allaire.jrun.http.WebEndpoint.run(WebEndpoint.java:107)
at allaire.jrun.ThreadPool.run(ThreadPool.java:267)
at allaire.jrun.WorkerThread.run(WorkerThread.java:74)

***********************************************************************
哪位高手帮帮忙!
感激万分!


...全文
67 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yunrong 2002-05-23
不愧是高手们
我找到问题所在了
是对空对象进行了操作,谢谢啦!
虽然分不多,请别见怪!
回复
可乐加水 2002-05-22
null
java.lang.NullPointerException基本上就是对空对象进行了操作,
所以在取得对象的时候应该先判断一下是不是为空的,按照Andrawu(Andrawu)的方法应该可以了
回复
Andrawu 2002-05-22
to weidegong(weidegong)
哪里哪里
回复
weidegong 2002-05-22
to Andrawu(Andrawu)
太敬业了

to yunrong (云容)
分不够?送你900分好了。。

回复
jspxnet 2002-05-22
有空
回复
wjfxiao 2002-05-22
如果userid是null,
user.length()肯定会报
java.lang.NullPointerException
用楼上的方法吧,应该没问题!
回复
Andrawu 2002-05-22
String userid=request.getParameter("userid")==null?"":request.getParameter("userid");
String password=request.getParameter("password")==null?"":request.getParameter("password");
String confirm_password=request.getParameter("confirm_password")==null?"":request.getParameter("confirm_password");
String question=request.getParameter("question")==null?"":request.getParameter("question");
String answer=request.getParameter("answer")==null?"":request.getParameter("answer");
String name=request.getParameter("name")==null?"":request.getParameter("name");
String sex=request.getParameter("sex")==null?"":request.getParameter("sex");
String literacy=request.getParameter("literacy")==null?"":request.getParameter("literacy");
String mail=request.getParameter("mail")==null?"":request.getParameter("mail");
String aihao=request.getParameter("aihao")==null?"":request.getParameter("aihao");

试试:
如果不行用
try{
.....
}catch(Exception se) {
se.printStackTrace(System.err);
}
得到错误的信息看看,还可以用out.println("aaa") ;一步一步的跟踪。
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告