我的环境变量设置如下:(帮我看看环境有没设错)
CATALINA:
E:\csm\tomcat5.0
CATALINA_HOME
E:\csm\tomcat5.0
CLASSPATH
.;%JDBC_HOME%\lib\mssqlserver.jar;%JDBC_HOME%\lib\msbase.jar;%JDBC_HOME%\lib\msutil.jar;%JA
VA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\common\lib\servlet.jar
JAVA_HOME
c:\j2sdk1.4.2
JDBC_HOME
C:\Program Files\Microsoft SQL Server 2000 JDBC
Path
%JAVA_HOME%\bin;C:\Program Files\Borland\Delphi7\Bin;C:\Program
Files\Borland\Delphi7\Projects\Bpl\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System3
2\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN
—————————————————————————————————————————————
jdbctest.jsp代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"
errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>jdbctest</title>
</head>
<body>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://192.168.18.122:1433;DatabaseName=test";
String user="sa";
String password="csm";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你\");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
————————————————————————————————————————————
jdbctest.jsp我放在tomcat5.0\webapps\root\下,WEB-INF\lib\下已有msbase.jar、mssqlserver.jar
、msutil.jar这三个文件;
运行:http://127.0.0.1:8080/test/test5/jdbctest.jsp 出现以下错误:
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: Unable to compile class for JSP
An error occurred at line: 24 in the jsp file: /test/test5/condb.jsp
Generated servlet error:
E:\csm\tomcat5.0\Tomcat
5.0\work\Catalina\localhost\_\org\apache\jsp\test\test5\condb_jsp.java:75: unclosed string
literal
out.print("?????????????????");
^
An error occurred at line: 24 in the jsp file: /test/test5/condb.jsp
Generated servlet error:
E:\csm\tomcat5.0\Tomcat
5.0\work\Catalina\localhost\_\org\apache\jsp\test\test5\condb_jsp.java:76: ')' expected
out.write('\r');
^
2 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
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.27 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.27
7 个解决方案
#1
("数据库操作成功,恭喜你\");
去掉\
去掉\
#2
conf/server.xml
在<!-- Tomcat Root Context -->加了
<Context path="/test" docBase="C:\Tomcat5.0\webapps\ROOT\test"
debug="5" reloadable="true" crossContext="true">
在<!-- Tomcat Root Context -->加了
<Context path="/test" docBase="C:\Tomcat5.0\webapps\ROOT\test"
debug="5" reloadable="true" crossContext="true">
#3
同意btut2004
#4
同意btut2004的意见
问题就是在这里
<%out.print("数据库操作成功,恭喜你\");%>
去掉\
<%out.print("数据库操作成功,恭喜你");%>
\是转义字符,\"使得out.print() 的""不配对
问题就是在这里
<%out.print("数据库操作成功,恭喜你\");%>
去掉\
<%out.print("数据库操作成功,恭喜你");%>
\是转义字符,\"使得out.print() 的""不配对
#5
把三个jar 放在 Tomcat 4.1\common\lib下试试
#6
可以了,非常感谢啊 参与有奖啊
#7
up
#1
("数据库操作成功,恭喜你\");
去掉\
去掉\
#2
conf/server.xml
在<!-- Tomcat Root Context -->加了
<Context path="/test" docBase="C:\Tomcat5.0\webapps\ROOT\test"
debug="5" reloadable="true" crossContext="true">
在<!-- Tomcat Root Context -->加了
<Context path="/test" docBase="C:\Tomcat5.0\webapps\ROOT\test"
debug="5" reloadable="true" crossContext="true">
#3
同意btut2004
#4
同意btut2004的意见
问题就是在这里
<%out.print("数据库操作成功,恭喜你\");%>
去掉\
<%out.print("数据库操作成功,恭喜你");%>
\是转义字符,\"使得out.print() 的""不配对
问题就是在这里
<%out.print("数据库操作成功,恭喜你\");%>
去掉\
<%out.print("数据库操作成功,恭喜你");%>
\是转义字符,\"使得out.print() 的""不配对
#5
把三个jar 放在 Tomcat 4.1\common\lib下试试
#6
可以了,非常感谢啊 参与有奖啊
#7
up