日期:2014-05-20  浏览次数:20906 次

修女重出江湖
小女子好段时间没学JAVA了,我的问题是JSP连接SQL2000有问题?
JAVA连接SQL成功,SQL打了SP4补丁,TOMCAT也能打开http://localhost:8000(因为先前8080端口据说被占用,我就改了),成功.jdbc驱动及路径都OK啊.
但我用的一个测试连接的JSP文件怎么就失败呢?请问各位大师!
注:我的sql_test.jsp是放在..\Tomcat 6.0\webapps\ROOT 下

出错信息提示如下
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: /sql_test.jsp(1,4) Invalid directive
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:499)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1426)
org.apache.jasper.compiler.Parser.parse(Parser.java:133)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
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:317)
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.14 logs.


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

Apache Tomcat/6.0.14
以下是我的JSP文件
<%@ 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";
   //pubs 为你的数据库的
   String user="sa";
   String password="";
   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> 

TOMCAT中LOG显示
 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /sql_test.jsp(1,4) Invalid directive
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:499)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1426)
at org.apache.jasper.compiler.Parser.parse(Parser.java:133)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)