日期:2014-05-18  浏览次数:20845 次

jsp与数据库连接问题
指点下   这是什么原因造成的阿   总是没法编译类
运行环境是:
win2003r2企业版
sqlserver2000   sp4
tomcat6
jdk6

测试能telnet   1433   网页能连接数据库

出错信息如下

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.JspCompilationContext.compile(JspCompilationContext.java:574)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root   cause  

java.io.UTFDataFormatException:   Invalid   byte   1   of   1-byte   UTF-8   sequence.
org.apache.jasper.xmlparser.UTF8Reader.invalidByte(UTF8Reader.java:621)
org.apache.jasper.xmlparser.UTF8Reader.read(UTF8Reader.java:492)
org.apache.jasper.xmlparser.XMLEncodingDetector.load(XMLEncodingDetector.java:1007)
org.apache.jasper.xmlparser.XMLEncodingDetector.skipString(XMLEncodingDetector.java:958)
org.apache.jasper.xmlparser.XMLEncodingDetector.scanXMLDecl(XMLEncodingDetector.java:1216)
org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:122)
org.apache.jasper.xmlparser.XMLEncodingDetector.getEncoding(XMLEncodingDetector.java:110)
org.apache.jasper.compiler.ParserController.determineSyntaxAndEncoding(ParserController.java:308)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:172)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Apache   Tomcat/6.0.10   logs.


--------------------------------------------

Apache   Tomcat/6.0.10


源代码如下

   <%@ page import= "java.lang.*, java.io.*, java.sql.*, java.util.* " contentType= "text/html;charset=gb2312 " %>
   <html>
   <body>
   <% Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
   String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs ";
    String user= "sa ";