首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

修女重出江湖解决思路

2013-09-11 
修女重出江湖小女子好段时间没学JAVA了,我的问题是JSP连接SQL2000有问题?JAVA连接SQL成功,SQL打了SP4补丁,

修女重出江湖
小女子好段时间没学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)


at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)


[解决办法]
<%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=gb2312" %> 

把里边的分开写一下吧
<%@ page lan...="java" pageEncoding="gb2312" %>
<%@ page import="java.lang.*, java.io.*, java.sql.*, java.util.*"%>

试试吧.没用过Tomcat6.0
[解决办法]
原因很简单,你的语句中使用的是中文的全角空格,把它们替换一下就可以了!

另外Class.forName 哪一行少了一个分号

Java code
<%@ 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>
[解决办法]
文件找不到错误~~改成<url-pattern>/hello </url-pattern>这样试试~~
[解决办法]
如果我没记错,你的项目启动的时候就会报错.url-patten里边的内容应该是以/开头
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行