新手求教,向数据库提交信息时出错。
不是自己写的代码,从一本书上照抄的实例,可是执行到这个用户注册提交信息的页面时就出错。
该jsp文件代码如下
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<%@ page contentType= "text/html; charset=gb2312 " %>
<%@ page import= "XiaoYuJob.util.*,java.sql.*,javax.servlet.http.HttpServletRequest "%>
<%//request.setCharacterEncoding( "GB2312 ");%>
<jsp:useBean id= "jobSeeker " class= "XiaoYuJob.job.JobSeeker " scope= "request " />
<!--构造jobSeeker类的对象 jobSeeker-->
<jsp:setProperty name= "jobSeeker " property= "* "/>
<!--设置对象jobSeeker的属性-->
<%
DealString str=new DealString();
ShowErrorBox show=new ShowErrorBox();
out.print( "sssss "+jobSeeker.getSusername());
if(jobSeeker.getPassword().equals( " ")||jobSeeker.getEmail().equals( " ")||jobSeeker.getBirthday().equals( " ")){
out.print(show.errorBox( "请添写完整信息! ", "错误信息 "));
return;
}else{
if(jobSeeker.getSusername().compareTo( "z ")> =0||jobSeeker.getSusername().compareTo( "0 ") <=0){
out.print(show.errorBox( "注册用户名不允许为特殊字符和汉字! ", "错误信息 "));
return;
}
/*DataBaseConn dbc=new DataBaseConn();
try
{
java.sql.Statement st=dbc.getStmt();
String sql= "INSERT INTO t_jobSeeker(auserName,trueName,age,sex,birthday, "+
"school,specialty,knowledge,email,resume) VALUES( ' "+
jobSeeker.getSusername()+ " ', ' "+
str.toGb(jobSeeker.getStruename())+ " ', ' "+jobSeeker.getAge()+ " ', ' "+
jobSeeker.getSex()+ " ', ' "+jobSeeker.getBirthday()+ " ', ' "+
str.toGb(jobSeeker.getSchool())+ " ', ' "+
str.toGb(jobSeeker.getSpecialty())+ " ', ' "+
str.toGb(jobSeeker.getKnowledge())+ " ', ' "+
jobSeeker.getEmail()+ " ', ' "+str.toGb(jobSeeker.getResume())+ " ') ";
st.addBatch(sql);
//添加一个sql语句进statement
sql= "insert into t_user (username,password,type)values( ' "+
jobSeeker.getSusername()+ " ', ' "+jobSeeker.getPassword()+ " ', '1 ') ";
st.addBatch(sql);
//添加一个sql语句进statement
st.executeBatch();
//批执行 上面添加的sql语句
out.print( " <script> alert( '修改成功! ');document.location= '../index.jsp '; </script> ");
return;
}catch(Exception e)
{
out.print(show.errorBox( "修改失败,数据库错误! ", "错误信息 "));
}*/
}
%>
出错提示如下
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.jobseeker.regDo_jsp._jspService(regDo_jsp.java:68)
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.30 logs.
--------------------------------------------
Apache Tomcat/5.0.30
[解决办法]
估计是jobSeeker中某个属性是空值 可以OUT.PRINT()打印下试试看是哪个属性为空
然后在进一步查找错误的根源
[解决办法]
空指针错误,某个对象为空引起
[解决办法]
out.print( "sssss "+jobSeeker.getSusername()); 就象你代码里的这句
把jobSeeker别的属性也打出来
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html