JSP连接 MS SQL 问。
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
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:572)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.
org.apache.jasper.xmlparser.UTF8Reader.invalidByte(UTF8Reader.java:620)
org.apache.jasper.xmlparser.UTF8Reader.read(UTF8Reader.java:491)
org.apache.jasper.xmlparser.XMLEncodingDetector.load(XMLEncodingDetector.java:999)
org.apache.jasper.xmlparser.XMLEncodingDetector.skipString(XMLEncodingDetector.java:950)
org.apache.jasper.xmlparser.XMLEncodingDetector.scanXMLDecl(XMLEncodingDetector.java:1208)
org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:120)
org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:108)
org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:304)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:169)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:155)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
--------------------------------------------
Apache Tomcat/5.5.20
<html>
<body>
<% Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs ";
//pubs 为你的数据库的
String user= "sa ";
String password= "admin ";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql= "select job_id,job_desc from jobs ";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) { %>
您的第一个字段内容为: <%=rs.getString(1)%> <br>
您的第二个字段内容为: <%=rs.getString(2)%> <br>
<% } %>
<% out.print( "数据库操作成功,恭喜你 "); %>
<% rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
CLASSPATH =
.;%JAVA_HOME%\lib;
%TOMCAT_HOME%\common\lib\servlet-api.jar;
%TOMCAT_HOME%\common\lib\jsp-api.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar
[解决办法]
你这个和数据库联接没什么关系,错在
java.io.UTFDataFormatException: Invalid byte 1 of 1-byte UTF-8 sequence.
看看是不是文件里面有什么非法字符,还有页面的pageEncoding是什么,设置成UTF-8看看
[解决办法]
一、把TOMCAT_HOME改为CATALINA_HOME
二、把页面上的中文字都去掉试试。
[解决办法]
是不是编码的问题啊,你的jsp上的encoding方式都设置好了?
[解决办法]
错误应该在页面上,楼主拿出来的代码不全吧。
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html