0

尝试将使用 JSP 从 html 页面检索到的数据插入到我的 MS Access 数据库中的表中时,我不断收到不同的错误。每次我尝试修复或更改我的代码时,我都会遇到不同的错误。当前的错误是:

(ps。我正在使用apache tomcat。我的数据库称为“tico”,“Contacts”是表的名称。MS访问中的字段名称是“Job Code:”和“Tico's Client:”)。如果有人可以提供帮助,将不胜感激。谢谢。:)

-------------------------------------------------------------------------
enter code here 

HTTP Status 500 - An exception occurred processing JSP page /TICo Website/onejsp.jsp     at line 21

type Exception report

message An exception occurred processing JSP page /TICo Website/onejsp.jsp at line 21

description The server encountered an internal error that prevented it from fulfilling     this request.``

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /TICo Website/onejsp.jsp at line 21

 18:      url = "jdbc:odbc:tico" 
 19: />
 20: 
 21: <sql:update var="tico" scope="request" dataSource ="${tico}">
 22:  INSERT INTO Contacts
 23:  ([Job Code:], [TICo's Client:])
 24:  VALUES (?, ?)

                                                                                            Stacktrace:  
                                                                                             org.apache.jasper.servlet.JspServletWrapper.handleJspException

(JspServletWrapper.java:521)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)        
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

 root cause

 javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get   
  connection, 
   DataSource invalid: "java.sql.SQLException: [Microsoft]
   [ODBC Driver Manager]           
    Data source name not found and no default driver specified"     
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException
   (PageContextImpl.java:865)

   org.apache.jasper.runtime.PageContextImpl.handlePageException
  (PageContextImpl.java:794)
   org.apache.jsp.TICo_0020Website.onejsp_jsp._jspService(onejsp_jsp.java:215)
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

   root cause

   javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid:
   "java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name 
   not found and   no     default driver specified"
  org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.
  getConnection(UpdateTagSupport.   java:243)
 org.apache.taglibs.standard.tag.common.sql.UpdateTagSupport.doStartTag
 (UpdateTagSupport.jav     a:124)

 org.apache.jsp.TICo_0020Website.onejsp_jsp._jspx_meth_sql_005fupdate_005f0
 (onejsp_jsp.java:    264)

org.apache.jsp.TICo_0020Website.onejsp_jsp._jspService(onejsp_jsp.java:80)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)    

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

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


----------------------------------------------------------------------------------
full stack trace
-------------------------------------------------------------------------------

enter code hereJun 25, 2013 9:54:33 AM   
org.apache.catalina.core.AprLifecycleListener    init 

INFO: The APR based Apache Tomcat Native library which allows optimal performance 

in production environments was not found on the java.library.path: C:\Program 
 Files\Apache    Software Foundation\Tomcat 6.0\bin;C:\Windows\Sun\Java\bin;C:

\Windows    \system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32
 \Wbem;C:\Windows    \System32\WindowsPowerShell\v1.0\;;.    

Jun 25, 2013 9:54:33 AM org.apache.coyote.http11.Http11Protocol init

INFO: Initializing Coyote HTTP/1.1 on http-8080

Jun 25, 2013 9:54:33 AM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 438 ms

Jun 25, 2013 9:54:33 AM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

Jun 25, 2013 9:54:33 AM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/6.0.37

Jun 25, 2013 9:54:33 AM org.apache.catalina.startup.HostConfig deployDescriptor

INFO: Deploying configuration descriptor manager.xml

Jun 25, 2013 9:54:33 AM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory docs

Jun 25, 2013 9:54:33 AM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory ROOT

Jun 25, 2013 9:54:34 AM org.apache.coyote.http11.Http11Protocol start

INFO: Starting Coyote HTTP/1.1 on http-8080

Jun 25, 2013 9:54:34 AM org.apache.jk.common.ChannelSocket init

INFO: JK: ajp13 listening on /0.0.0.0:8009

Jun 25, 2013 9:54:34 AM org.apache.jk.server.JkMain start

INFO: Jk running ID=0 time=0/15  config=null

Jun 25, 2013 9:54:34 AM org.apache.catalina.startup.Catalina start

 INFO: Server startup in 800 ms

Jun 25, 2013 10:03:14 AM org.apache.coyote.http11.Http11Protocol pause

INFO: Pausing Coyote HTTP/1.1 on http-8080

Jun 25, 2013 10:03:15 AM org.apache.catalina.core.StandardService stop

INFO: Stopping service Catalina

Jun 25, 2013 10:03:15 AM org.apache.coyote.http11.Http11Protocol destroy

INFO: Stopping Coyote HTTP/1.1 on http-8080

Jun 25, 2013 10:03:21 AM org.apache.catalina.core.AprLifecycleListener init   

INFO: The APR based Apache Tomcat Native library which allows optimal performance 

in production environments was not found on the java.library.path: C:\Program 

Files\Apache   Software Foundation\Tomcat 6.0\bin;C:\Windows\Sun\Java\bin;C:\Windows  

\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:
\Windows   \System32\WindowsPowerShell\v1.0\;;.   

Jun 25, 2013 10:03:21 AM org.apache.coyote.http11.Http11Protocol init

INFO: Initializing Coyote HTTP/1.1 on http-8080

Jun 25, 2013 10:03:21 AM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 348 ms

Jun 25, 2013 10:03:21 AM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

Jun 25, 2013 10:03:21 AM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/6.0.37

Jun 25, 2013 10:03:21 AM org.apache.catalina.startup.HostConfig deployDescriptor

INFO: Deploying configuration descriptor manager.xml

Jun 25, 2013 10:03:21 AM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory docs

Jun 25, 2013 10:03:21 AM org.apache.catalina.startup.HostConfig deployDirectory

INFO: Deploying web application directory ROOT

Jun 25, 2013 10:03:22 AM org.apache.coyote.http11.Http11Protocol start

INFO: Starting Coyote HTTP/1.1 on http-8080

Jun 25, 2013 10:03:22 AM org.apache.jk.common.ChannelSocket init

INFO: JK: ajp13 listening on /0.0.0.0:8009

Jun 25, 2013 10:03:22 AM org.apache.jk.server.JkMain start

INFO: Jk running ID=0 time=0/15  config=null

Jun 25, 2013 10:03:22 AM org.apache.catalina.startup.Catalina start

INFO: Server startup in 495 ms`

JSP 页面

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<html>
<head>
<title>Using GET and POST Method to Read Form Data</title>
</head>
<body>                  

<sql:setDataSource
    var = "tico" 
    scope = "session" 
    driver = "sun.jdbc.odbc.JdbcOdbcDriver"
    url = "jdbc:odbc:tico" 
 />

 <sql:update var="tico" scope="request" dataSource ="${tico}">
 INSERT INTO Contacts
 (Job Code:, TICo's Client:)
 VALUES (?, ?)
 <sql:param value = "${param.jobcode}" />
 <sql:param value = "${param.ticosclient}" />
 </sql:update>  

 <center>
 <h1>Using GET Method to Read Form Data</h1>
 <div style="position:absolute; top:20px; width:100%; height:80px;">
 <ul>
 <table align='center' style="width: 1000px; height: 81px;" border="0" cellpadding="0" 
  cellspacing="0" align="center">
  <col width="33">
  <col width="33">
   <col width="33">
   <col width="33"></br></br></br>

<tr><td>     
<li><p><b>Job Code:</b>
   <%= request.getParameter("jobcode")%>
</p></li>
</td></tr>

<tr><td>
<li><p><b>TICo's Client:</b>
   <%= request.getParameter("ticosclient")%>
</p></li>
</td></tr>

</body>
</html>
4

1 回答 1

0

当然,您需要修复的一件事是您的 SQL 命令文本。

INSERT INTO Contacts
(Job Code:, TICo's Client:)
VALUES (?, ?)

将不得不更改为

INSERT INTO Contacts
([Job Code:], [TICo's Client:])
VALUES (?, ?)

顺便说一句,您可能需要仔细检查:字段名称中是否真的有冒号 ( ) 字符。这对于表单上的标签来说是很正常的,但是将它们包含在实际的字段名称中是相当不寻常的。

编辑

“未找到数据源名称且未指定默认驱动程序”错误表明 JSP 进程正在 64 位环境中运行,并且尚未在服务器。要更正此问题,请从此处下载并安装 64 位版本的 Access 数据库引擎,然后为数据库创建一个 64 位系统 DSN(通过普通的 Windows 控制面板小程序,而不是 SYSWOW64)。

于 2013-06-24T15:06:35.027 回答