MS SQL 2005를 Eclipse에 연결하는 방법과 Tomcat 7을 내 서버로 연결하는 방법을 이해하기 위해이 코드를 사용하려고합니다. 나는 단지 java 웹 애플리케이션을 만드는 데있어 새로운 것이므로 나와 함께 참아주십시오. 아래 오류에서 어떻게 오류의 원인을 추적 할 수 있습니까? 프로젝트에는 2 개의 JSP 파일과 3 개의 클래스 파일이 있습니다. index.jsp
, result.jsp
, SQLConnection.java
, Items.java
및 ItemController.java
.HTTP 상태 500 오류입니다. Eclipse + Tomcat + MS SQL 2005
,
type Exception report
message
description The server encountered an internal error() that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.NullPointerException
connection.SQLConnection.execSelectQuery(SQLConnection.java:35)
model.Item.lastItems(Item.java:10)
org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
SQLConnection.java 및 index.jsp에 대한 코드는 다음과 같다;
SQLConnection.java
package connection;
import java.sql.*;
public class SQLConnection {
protected Connection con=null;
protected ResultSet rs=null;
public SQLConnection(String address)
{
try
{
String conString = "jdbc:sqlserver://localhost:1433;databaseName=Chingdb; integratedSecurity=true;";
con = DriverManager.getConnection(conString);
}catch(SQLException sqlError){
//ERROR MANAGEMENT HERE
}
}
public boolean execQuery(String sql)
{
boolean result = false;
try
{
Statement stmt = con.createStatement();
stmt.execute(sql);
result = true;
}catch(SQLException sqlError){
//ERROR MANAGEMENT HERE
result = false;
}
return result;
}
public void execSelectQuery(String sql)
{
try
{
Statement stmt = con.createStatement();
this.rs = stmt.executeQuery(sql);
}catch(SQLException sqlError){
//ERROR MANAGEMENT HERE
}
}
public void disconnect()
{
try
{
con.close();
}catch(SQLException sqlError){
//ERROR MANAGEMENT HERE
}
}
}
index.jsp를
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org /TR/html4/loose.dtd">
<%@page import="model.Item"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Todo-List App</title>
</head>
<body>
<h2>Add a new item</h2>
<form action="addItem" method="post">
<table>
<tr>
<td><input type="text" value="I have to..." onClick="this.value('')" name="todo"/></td>
<td><input type="submit" value="Send" name="send"/> </td>
</tr>
</table>
</form>
<h2>Todo-List</h2>
<%
Item item = new Item();
String[] lastest = item.lastItems();
for(int i=0;i<lastest.length;i++)
{%>
<%=lastest[i] %> <br>
<%}item.disconnect();
%>
</body>
</html>
여기에 관련 코드를 추가하십시오. – gks