[Tomcat] kan servlet niet vinden

Pagina: 1
Acties:

  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
Ik ben nu al meer dan drie dagen bezig, om alleen het voorbeeldje van de Tomcat handleiding aan het werk te krijgen. Alles wat in de handleiding is beschreven heb ik gedaan, maar nog werkt het niet. Als ik een servletje in de example-map zet werkt hij wel.

Maar bij het voorbeeldje voor connectie met MySQL werkt hij niet. Hij maakt hier gebruik van een map 'DBTest'. Ik heb een MySQL draaiend. Ik heb de server.xml aangepast (zoals aangegeven in de handleiding).

Ik heb in Tomcat in de admin-tool dit opgegeven:
JNDI Name: jdbc/TestDB
Data Source URL: jdbc:mysql://localhost:3306/javatest?autoReconnect=true
JDBC Driver Class: org.gjt.mm.mysql.Driver

Ik heb in de map ....\TomCat\webapps\DBTest\WEB-INF de Web.xml aangepast:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<description>MySQL Test App</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

Kan iemand me vertellen waarom hij nog steeds de servlet niet kan vinden??

  • Woy
  • Registratie: April 2000
  • Niet online

Woy

Moderator Devschuur®
Kan hij je servlet niet vinden of is het een probleem met de Database.
Als het probleem is dat hij de class niet kan vinden probeer dan eerst eens een simpel Servletje die alleen wat op het scherm print ofzo. Dan sluit je ieder geval alle andere problemen uit.

En plaats anders de Exception even want dan kunnen we beter zien wat er mis gaat.

[ Voor 15% gewijzigd door Woy op 02-09-2004 10:18 ]

“Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.”


  • XKB
  • Registratie: Oktober 1999
  • Laatst online: 05-04-2021

XKB

Anonymous functional

Staat de jdbc jar ook in je classpath?

Choose for Choice! Choose Linux! | src van icon


  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
Ik heb geen JDBC.jar... moet ik die hebben?
Ik heb MyODBC geïnstalleerd en ik heb geprobeerd JDBC te installeren, maar in dat installatiepakket zit ook geen JDBC.jar...
Dus als ik die nodig ben, waar kan ik die dan vinden?

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 23:25

Janoz

Moderator Devschuur®

!litemod

Om mysql te kunnen gebruiken zul je bij mysql.com ergens de mysql jdbc connector jar moeten downlaoden en in de libs van tomcat zetten. Anders weet hij immers helemaal niet hoe hij moet verbinden met mysql. Als het goed is is dit ook al duidelijk naar voren gekomen in de logs (dat hij org/gjt/mm/mysql/Driver.class of com/mysql/jdbc/Driver.class niet kan vinden)

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
Als ik kleine (werkende) servlets naar die map kopieer doen die het ook niet...
(Die zou ik dan toch gewoon moeten kunnen aanroepen met:
http://127.0.0.1:8080/DBTest/servlet ?)

  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
(En Driver.class staat wel in de class path, dus dat is wel goed)

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 23:25

Janoz

Moderator Devschuur®

!litemod

Definieer 'doet het niet' nu eens. Daar kunnen we helemaal niks mee.

Zodra je een servlet neerzet en de mapping toevoegd in je web.xml hoort hij inderdaad te werken. Dat Driver.class wel in het classpath staat zegt helemaal niks. org.gjt.mm.mysql.Driver of com.mysql.jdbc.Driver moet in het claspath staan. Hetzij via een jar, hetzij via de volledige directory structuur.

Lees logs, probeer foutmeldingen te begrijpen en geef ook hier meer relevante informatie wat er precies fout gaat.

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
Hoewel er hier veel mensen zijn die met tomcat hebben zitten tweaken hoort dit volgens mij onder Software Algemeen thuis, omdat het een configuratieprobleem is, niet een programmeerprobleem.

Probeer de suggestie van rwb eens uit en geef hier weer aan wat het resultaat is.
Het is waarschijnlijk een probleem met het standaard servlet path van je webapp.

En geef eens de foutmelding die je krijgt, misschien kan ik er dan meer over zeggen.

  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
In Software Algemeen zit volgens mij niemand die hier verstand van heeft...
En jullie zijn allemaal zo slim (slijm slijm)...

Maar goed, verdere info:

De Browser zegt dit:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 6 in the jsp file: /index.jsp

Generated servlet error:
....[javac] Compiling 1 source file

C:\Program Files\TomCat\work\Standalone\localhost\DBTest\index_jsp.java:48: cannot resolve symbol
symbol : class DBTest
location: class org.apache.jsp.index_jsp
DBTest tst = new DBTest();
^

En de Tomcat-output is:
Compile failed, ...

En hier is de log-file:
2004-09-02 11:09:16 StandardContext[/DBTest]: Starting
2004-09-02 11:09:16 StandardContext[/DBTest]: Processing start(), current available=false
2004-09-02 11:09:16 StandardContext[/DBTest]: Configuring default Resources
2004-09-02 11:09:16 StandardContext[/DBTest]: Configuring non-privileged default Loader
2004-09-02 11:09:16 StandardContext[/DBTest]: Configuring default Manager
2004-09-02 11:09:16 StandardContext[/DBTest]: Processing standard container startup
2004-09-02 11:09:16 WebappLoader[/DBTest]: Deploying class repositories to work directory C:\Program Files\TomCat\work\Standalone\localhost\DBTest
2004-09-02 11:09:16 WebappLoader[/DBTest]: Deploy class files /WEB-INF/classes to C:\Progra~1\TomCat\webapps\DBTest\WEB-INF\classes
2004-09-02 11:09:16 WebappLoader[/DBTest]: Deploy JAR /WEB-INF/lib/foo.jar to C:\Progra~1\TomCat\webapps\DBTest\WEB-INF\lib\foo.jar
2004-09-02 11:09:16 WebappLoader[/DBTest]: Reloading checks are enabled for this Context
2004-09-02 11:09:16 ContextConfig[/DBTest]: ContextConfig: Processing START
2004-09-02 11:09:16 StandardContext[/DBTest]: Setting deployment descriptor public ID to '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
2004-09-02 11:09:17 StandardContext[/DBTest]: Setting deployment descriptor public ID to '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
2004-09-02 11:09:17 ContextConfig[/DBTest]: Accumulating TLD resource paths
2004-09-02 11:09:17 ContextConfig[/DBTest]: Scanning <taglib> elements in web.xml
2004-09-02 11:09:17 ContextConfig[/DBTest]: Scanning TLDs in /WEB-INF subdirectory
2004-09-02 11:09:17 ContextConfig[/DBTest]: Scanning JARs in /WEB-INF/lib subdirectory
2004-09-02 11:09:17 ContextConfig[/DBTest]: Adding path '/WEB-INF/lib/foo.jar'
2004-09-02 11:09:17 ContextConfig[/DBTest]: Scanning JAR at resource path '/WEB-INF/lib/foo.jar'
2004-09-02 11:09:17 ContextConfig[/DBTest]: Pipline Configuration:
2004-09-02 11:09:17 ContextConfig[/DBTest]: org.apache.catalina.core.StandardContextValve/1.0
2004-09-02 11:09:17 ContextConfig[/DBTest]: ======================
2004-09-02 11:09:17 NamingContextListener[/Standalone/localhost/DBTest]: Creating JNDI naming context
2004-09-02 11:09:17 NamingContextListener[/Standalone/localhost/DBTest]: Resource parameters for jdbc/TestDB = ResourceParams[name=jdbc/TestDB, parameters={factory=org.apache.commons.dbcp.BasicDataSourceFactory, maxActive=100, maxWait=10000, password=javadude, url=jdbc:mysql://localhost:3306/javatest?autoReconnect=true, driverClassName=org.gjt.mm.mysql.Driver, maxIdle=30, username=javauser}]
2004-09-02 11:09:17 NamingContextListener[/Standalone/localhost/DBTest]: Adding resource ref jdbc/TestDB
2004-09-02 11:09:17 NamingContextListener[/Standalone/localhost/DBTest]: ResourceRef[className=javax.sql.DataSource,factoryClassLocation=null,factoryClassName=org.apache.naming.factory.ResourceFactory,{type=scope,content=Shareable},{type=auth,content=Container},{type=factory,content=org.apache.commons.dbcp.BasicDataSourceFactory},{type=maxActive,content=100},{type=maxWait,content=10000},{type=password,content=javadude},{type=url,content=jdbc:mysql://localhost:3306/javatest?autoReconnect=true},{type=driverClassName,content=org.gjt.mm.mysql.Driver},{type=maxIdle,content=30},{type=username,content=javauser}]
2004-09-02 11:09:17 NamingContextListener[/Standalone/localhost/DBTest]: Resource parameters for UserTransaction = null
2004-09-02 11:09:17 StandardManager[/DBTest]: Seeding random number generator class java.security.SecureRandom
2004-09-02 11:09:17 StandardManager[/DBTest]: Seeding of random number generator has been completed
2004-09-02 11:09:17 StandardContext[/DBTest]: Posting standard context attributes
2004-09-02 11:09:17 StandardContext[/DBTest]: Configuring application event listeners
2004-09-02 11:09:17 StandardContext[/DBTest]: Sending application start events
2004-09-02 11:09:17 StandardContext[/DBTest]: Starting filters
2004-09-02 11:09:17 StandardWrapper[/DBTest:default]: Loading container servlet default
2004-09-02 11:09:17 StandardWrapper[/DBTest:invoker]: Loading container servlet invoker
2004-09-02 11:09:17 StandardContext[/DBTest]: Starting completed
2004-09-02 11:09:23 StandardContext[/DBTest]: Mapping contextPath='/DBTest' with requestURI='/DBTest/index.jsp' and relativeURI='/index.jsp'
2004-09-02 11:09:23 StandardContext[/DBTest]: Trying exact match
2004-09-02 11:09:23 StandardContext[/DBTest]: Trying prefix match
2004-09-02 11:09:23 StandardContext[/DBTest]: Trying extension match
2004-09-02 11:09:23 StandardContext[/DBTest]: Mapped to servlet 'jsp' with servlet path '/index.jsp' and path info 'null' and update=true
2004-09-02 11:09:24 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 6 in the jsp file: /index.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Program Files\TomCat\work\Standalone\localhost\DBTest\index_jsp.java:48: cannot resolve symbol
symbol : class DBTest
location: class org.apache.jsp.index_jsp
DBTest tst = new DBTest();
^


An error occurred at line: 6 in the jsp file: /index.jsp

Generated servlet error:
C:\Program Files\TomCat\work\Standalone\localhost\DBTest\index_jsp.java:48: cannot resolve symbol
symbol : class DBTest
location: class org.apache.jsp.index_jsp
DBTest tst = new DBTest();
^
2 errors


at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)

  • bodiam
  • Registratie: December 2001
  • Laatst online: 31-12-2024
Dat betekent dus dat hij de classfile niet kan vinden.

Wat je moet hebben is een classfile in de WEB-INF/classes directory van de webapp waarin de jsp staat. Om de DB class vervolgens aan de roepen dien je hem te importeren in de JSP pagina.
Die import is zoiets als: <%@ page import="test.util.DBTest" %> als je classfile er zo uit ziet:

Java:
1
2
3
4
5
6
7
package test.util;

public class DBTest
{

  // ..etc
}

  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
Help allemaal niet...

Als ik het in een package doe, vindt hij de package niet.

En dit heb ik in de jsp staan
<html>
<head>
<title>DB Test</title>
</head>
<body>
<%
test.DBTest tst = new test.DBTest();
tst.init();
%>

<h2>Results</h2>
Foo <%= tst.getFoo() %><br/>
Bar <%= tst.getBar() %>

</body>
</html>

  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
waar heb je je class file neergezet?

  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
C:\Program Files\TomCat\webapps\DBTest\WEB-INF\classes
en de package in
C:\Program Files\TomCat\webapps\DBTest\WEB-INF\lib

  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
je weet neem ik aan dat als je een package maakt dat je hem dan in een directory moet plaatsen zoals je package gedefinieerd is? Dus als je een package test hebt, dan moet de classfile in classes/test/

En ik neem aan dat jij in je vorige reply met package de jar file bedoelt?

  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
Nee dat weet ik niet...

En ja, ik bedoel de jar

  • bigbeng
  • Registratie: Augustus 2000
  • Laatst online: 26-11-2021
Dat had je trouwens in de documentatie kunnen vinden:

http://jakarta.apache.org...dard%20Directory%20Layout

Maar goed, ik neem aan dat je eerst zonder package werkte en dat had het gewoon moeten doen. Hoe is de situatie nu?

  • TweakerWannabe
  • Registratie: Februari 2002
  • Laatst online: 15-05-2023
Hmm, een dozijn aan andere fouten...
Maar hij vindt hem in ieder geval wel...

Zal ik eerst weer eens verder prutsen, kan hier wel een slotje op....

  • Woy
  • Registratie: April 2000
  • Niet online

Woy

Moderator Devschuur®
Als er een oplossing is hoeft er niet direct een slotje op een topic. Mischien heeft iemand anders nog wel een vraag over dit probleem en dan kan hij mooi dit topic ervoor gebruiken in plaats van een nieuwe te openen.

“Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.”

Pagina: 1