jsp初学者提问:jsp文件出现HTTP500错误怎么解决, 50
HTTPStatus500-typeExceptionreportmessagedescriptionTheserverencounteredaninternalerro...
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.subjectsave_jsp._jspService(subjectsave_jsp.java:78)
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.28 logs.
原文件为:<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ page import="com.study.database.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'examsave.jsp' starting page</title>
</head>
<body>
<%
DBConnectionManage db = new DBConnectionManage();
Connection conn = db.getFreeConnection();
String subjecttype = request.getParameter("subjecttype");
String subjectquestion = request.getParameter("subjectquestion");
String subjectanswer = request.getParameter("subjectanswer");
String query = "insert into subject (subjecttype,subjectquestion,subjectanswer) values(?,?,?)";
PreparedStatement psmt = null;
try{
psmt = conn.prepareStatement(query);
psmt.setString(1,subjecttype);
psmt.setString(2,subjectquestion);
psmt.setString(3,subjectanswer);
psmt.executeUpdate();
out.println("<script language = javascript>alert('操作记录成功!');window.location.href='subject.jsp';</script>");
psmt.close();
}catch(Exception ex){
}finally{
psmt.close();
conn.close();
}
%>
</body>
</html>
就下面这行出错了。
finally{
psmt.close();
conn.close();
} 展开
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.subjectsave_jsp._jspService(subjectsave_jsp.java:78)
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.28 logs.
原文件为:<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ page import="com.study.database.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'examsave.jsp' starting page</title>
</head>
<body>
<%
DBConnectionManage db = new DBConnectionManage();
Connection conn = db.getFreeConnection();
String subjecttype = request.getParameter("subjecttype");
String subjectquestion = request.getParameter("subjectquestion");
String subjectanswer = request.getParameter("subjectanswer");
String query = "insert into subject (subjecttype,subjectquestion,subjectanswer) values(?,?,?)";
PreparedStatement psmt = null;
try{
psmt = conn.prepareStatement(query);
psmt.setString(1,subjecttype);
psmt.setString(2,subjectquestion);
psmt.setString(3,subjectanswer);
psmt.executeUpdate();
out.println("<script language = javascript>alert('操作记录成功!');window.location.href='subject.jsp';</script>");
psmt.close();
}catch(Exception ex){
}finally{
psmt.close();
conn.close();
}
%>
</body>
</html>
就下面这行出错了。
finally{
psmt.close();
conn.close();
} 展开
5个回答
展开全部
注意一下java.lang.NullPointerException 这个异常,
检查一下
String subjecttype = request.getParameter("subjecttype");
String subjectquestion = request.getParameter("subjectquestion");
String subjectanswer = request.getParameter("subjectanswer");
是不是其中哪个值是空的。
检查一下
String subjecttype = request.getParameter("subjecttype");
String subjectquestion = request.getParameter("subjectquestion");
String subjectanswer = request.getParameter("subjectanswer");
是不是其中哪个值是空的。
展开全部
可以去tomcat的temp下看org.apache.jsp.subjectsave_jsp._jspService(subjectsave_jsp.java:78)这个错误在哪行代码,你可以去掉页面的java代码来判断是不是配置文件错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
估计是psmt = conn.prepareStatement(query);这行引起的,conn可能为null,你可以system。out打印一下。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
psmt.executeUpdate();
out.println("<script language = javascript>alert('操作记录成功!');window.location.href='subject.jsp';</script>");
psmt.close();
}catch(Exception ex){
}finally{
这里已经做了一次关闭psmt了,你后面怎么还关闭?
out.println("<script language = javascript>alert('操作记录成功!');window.location.href='subject.jsp';</script>");
psmt.close();
}catch(Exception ex){
}finally{
这里已经做了一次关闭psmt了,你后面怎么还关闭?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
psmt = conn.prepareStatement(query);
放到try的外面
放到try的外面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询