[問題] jsp連接sql遇到之問題
今天在寫jsp連接到資料庫sql的程式。
程式如下
<%}
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
out.println("有驅動程式24 ");
}
catch(ClassNotFoundException ce)
{
out.println("無驅動程式21232 ");
}
Connection h=null;
h = DriverManager.getConnection(""+ +
"jdbc:sqlserver://localhost:1433;user=****;password=****;database=A01");
%>
然而在DriverManager.getConnection 這個步驟遇到問題,我之前有用完全一樣的
程式碼,在以java寫 jdbc並有成功連上。但不知為何在tomcat上的jsp檔就出了問題。
差別之一可能是我先前的java語言是在eplice上撰寫,而jsp檔並不是
(但不知和這個有無相關。) 實際錯誤訊息如下:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message org.apache.jasper.JasperException: Unable to compile class for JSP
Description The server encountered an unexpected condition that prevented it
from fulfilling the request.
Exception
org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable
to compile class for JSP
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:404)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:619)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:383)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.lang.IllegalStateException: java.io.IOException:
java.lang.reflect.InvocationTargetException
org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:101)
org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:256)
org.apache.catalina.webresources.StandardRoot.getResourceInternal(StandardRoot.java:281)
org.apache.catalina.webresources.Cache.getResource(Cache.java:62)
org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:216)
org.apache.catalina.webresources.StandardRoot.getClassLoaderResource(StandardRoot.java:225)
org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1087)
org.apache.jasper.servlet.JasperLoader.getResourceAsStream(JasperLoader.java:139)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:198)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:183)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:1094)
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:129)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:457)
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:838)
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:387)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:437)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:419)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:460)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:383)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.io.IOException: java.lang.reflect.InvocationTargetException
org.apache.tomcat.util.compat.Jre9Compat.jarFileNewInstance(Jre9Compat.java:212)
org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:149)
org.apache.catalina.webresources.AbstractArchiveResourceSet.openJarFile(AbstractArchiveResourceSet.java:307)
org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:97)
org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:256)
org.apache.catalina.webresources.StandardRoot.getResourceInternal(StandardRoot.java:281)
org.apache.catalina.webresources.Cache.getResource(Cache.java:62)
org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:216)
org.apache.catalina.webresources.StandardRoot.getClassLoaderResource(StandardRoot.java:225)
org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1087)
org.apache.jasper.servlet.JasperLoader.getResourceAsStream(JasperLoader.java:139)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:198)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:183)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:1094)
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:129)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:457)
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:838)
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:387)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:437)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:419)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:460)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:383)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.lang.reflect.InvocationTargetException
java.base/jdk.internal.reflect.GeneratedConstructorAccessor9.newInstance(Unknown
Source)
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
org.apache.tomcat.util.compat.Jre9Compat.jarFileNewInstance(Jre9Compat.java:209)
org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:149)
org.apache.catalina.webresources.AbstractArchiveResourceSet.openJarFile(AbstractArchiveResourceSet.java:307)
org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:97)
org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:256)
org.apache.catalina.webresources.StandardRoot.getResourceInternal(StandardRoot.java:281)
org.apache.catalina.webresources.Cache.getResource(Cache.java:62)
org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:216)
org.apache.catalina.webresources.StandardRoot.getClassLoaderResource(StandardRoot.java:225)
org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1087)
org.apache.jasper.servlet.JasperLoader.getResourceAsStream(JasperLoader.java:139)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:198)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:183)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:1094)
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:129)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:457)
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:838)
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:387)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:437)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:419)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:460)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:383)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.nio.file.NoSuchFileException:
C:\Users\User\Desktop\apache-tomcat-9.0.12\webapps\ROOT\WEB-INF\lib\sqljdbc41.jar
java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:53)
java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:38)
java.base/sun.nio.fs.WindowsFileSystemProvider.readAttributes(WindowsFileSystemProvider.java:194)
java.base/java.nio.file.Files.readAttributes(Files.java:1755)
java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1220)
java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:727)
java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:845)
java.base/java.util.zip.ZipFile.<init>(ZipFile.java:245)
java.base/java.util.zip.ZipFile.<init>(ZipFile.java:175)
java.base/java.util.jar.JarFile.<init>(JarFile.java:341)
java.base/jdk.internal.reflect.GeneratedConstructorAccessor9.newInstance(Unknown
Source)
java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
org.apache.tomcat.util.compat.Jre9Compat.jarFileNewInstance(Jre9Compat.java:209)
org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:149)
org.apache.catalina.webresources.AbstractArchiveResourceSet.openJarFile(AbstractArchiveResourceSet.java:307)
org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:97)
org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:256)
org.apache.catalina.webresources.StandardRoot.getResourceInternal(StandardRoot.java:281)
org.apache.catalina.webresources.Cache.getResource(Cache.java:62)
org.apache.catalina.webresources.StandardRoot.getResource(StandardRoot.java:216)
org.apache.catalina.webresources.StandardRoot.getClassLoaderResource(StandardRoot.java:225)
org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1087)
org.apache.jasper.servlet.JasperLoader.getResourceAsStream(JasperLoader.java:139)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:198)
org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:183)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createPackage(LookupEnvironment.java:1094)
org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:129)
org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:457)
org.eclipse.jdt.internal.compiler.Compiler.internalBeginToCompile(Compiler.java:838)
org.eclipse.jdt.internal.compiler.Compiler.beginToCompile(Compiler.java:387)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:437)
org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:419)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:460)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:392)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:383)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
希望各位不吝提點問題出在何處,謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.129.149
※ 文章網址: https://www.ptt.cc/bbs/java/M.1540556759.A.97F.html
→
10/26 21:21,
6年前
, 1F
10/26 21:21, 1F
我安裝的java是java10.0.1 tomcat是9.0.12 請問這樣否會出問題呢
※ 編輯: a46911a149 (140.113.129.149), 10/26/2018 21:54:51
→
10/26 22:24,
6年前
, 2F
10/26 22:24, 2F
推
10/27 07:32,
6年前
, 3F
10/27 07:32, 3F
→
10/27 13:40,
6年前
, 4F
10/27 13:40, 4F
→
10/27 13:40,
6年前
, 5F
10/27 13:40, 5F
→
10/27 15:05,
6年前
, 6F
10/27 15:05, 6F
→
10/27 15:05,
6年前
, 7F
10/27 15:05, 7F
→
10/27 15:05,
6年前
, 8F
10/27 15:05, 8F
→
11/08 16:29,
6年前
, 9F
11/08 16:29, 9F
→
11/08 17:02,
6年前
, 10F
11/08 17:02, 10F
→
11/08 17:02,
6年前
, 11F
11/08 17:02, 11F
java 近期熱門文章
PTT數位生活區 即時熱門文章