jsp出一点问题,进来看看!
代码如下:
<%@ page contentType= "text/html; charset=gb2312 " language= "java "
import= "java.sql.*,java.util.*,xuanke.* " errorPage= " " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
</head>
<jsp:useBean id= "kecheng " class= "xuanke.Kecheng "scope= "request "/>
<jsp:useBean id= "xuanke " class= "xuanke.Xuanke "scope= "request "/>
<jsp:useBean id= "kechengbean " class= "xuanke.KechengBean "scope= "request "/>
<jsp:useBean id= "xuankebean " class= "xuanke.XuankeBean "scope= "request "/>
<body>
<%
int score=0;
String sno=request.getParameter( "sno ");
String coursecode=request.getParameter( "coursecode ");
if(sno==null){
sno= " ";
}
if(coursecode==null){
coursecode= " ";
}
Xuanke xuankee=new Xuanke();
xuankee.setSno(sno);
xuankee.setCoursecode(coursecode);
Kecheng g=kechengbean.getKechengScore(coursecode);//这里是关键,
score=score+g.getCredithour();//不知正
xuankee.setScoresum(score);//不正确
try{
xuankebean.setXuanke(xuankee);
xuankebean.addXuanke();
}catch(Exception e)
{
out.println(e.getMessage());
}
%>
<center>
<h1>
添加选课成功
</h1>
</center>
<a href= "student.jsp "> 返回 </a>
</body>
</html>
相关的bean:
public Kecheng getKechengScore(String coursecode)throws Exception
{
Statement stmt=con.createStatement();
ResultSet result=stmt.executeQuery( "select * from kecheng where coursecode= ' "+coursecode+ " ' ");
while(result.next())
{
String coursecode1=result.getString( "coursecode ");
String coursename1=result.getString( "coursename ");
int credithour1=Integer.parseInt(result.getString( "credithour "));
int maxstudents1=Integer.parseInt(result.getString( "maxstudents "));
Kecheng ke=new Kecheng();
ke.setCoursecode(coursecode1);
ke.setCoursename(coursename1);
ke.setCredithour(credithour1);
ke.setMaxstudents(maxstudents1);
}
return ke;
}
public void addXuanke()throws Exception
{
try{
int hh=msg.getScoresum();
String ret= "insert into xuanke values(?,?,?) ";
PreparedStatement stm=con.prepareStatement(ret);
stm.setString(1,msg.getSno());
stm.setString(2,msg.getCoursecode());
String gg=Integer.toString(hh);
stm.setString(3,gg);
try{
stm.execute();
}catch(Exception e)
{}
con.close();
} catch(Exception e)
{
e.printStackTrace();
throw e;
}
}
出现问题:
java.lang.NullPointerException
org.apache.jsp.xuanke_005fdo_jsp._jspService(xuanke_005fdo_jsp.java:126)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
[解决办法]
upppp
[解决办法]
空指针错误,也就是说你调用了一个空对象的某个方法,具体要看你服务器里面的此jsp对应的临时文件的126行,你把临时文件贴上来
[解决办法]
Kecheng g=kechengbean.getKechengScore(coursecode);这行的g能取得到值吗?
g取不到值然后下行g.getCredithour();自然会报空指针的异常;
score=score+g.getCredithour();
[解决办法]
取不到值而又没报错可能是( "select * from kecheng where coursecode= ' "+coursecode+ " ' ");这句SQL没挑到值:)
BTW:原来LZ是MM??