Newsgroup: it.comp.java
Titolo: Esecuzione Servlet sotto Tomcat

Salve sono un neofita di Servlet Java e non so come eseguire la 
seguente servlet :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CiaoMondoServlet extends HttpServlet{
	public void doGet(HttpServletRequest 
request,HttpServletResponse response)
		throws IOException,ServletException{
			PrintWriter out = response.getWriter();
			out.println("Ciao Mondo");
		}
}//fine class
premetto che ho installato Tomcat 5.5.1, ed ho posizionato il 
file.class sotto la seguente directory:
C:\Programmi\Apache Software Foundation\Tomcat 5.5
\webapps\ROOT\prove\WEB-INF\classes
Ho scaricato il file web.xml e l'ho posizionato sotto :
C:\Programmi\Apache Software Foundation\Tomcat 5.5
\webapps\ROOT\prove\WEB-INF
ma non so come compilarlo
qualche anima pia potrebbe aiutarmi ???
-- 
Inviato da Virgilio 
http://newsgroup.virgilio.it
Filtra gli antipatici, segnala le risposte, segue i thread, e tutto da web

 qualche anima pia potrebbe aiutarmi ???
a questo punto :
1) avvia Tomcat
2) punta il browser a 
http://localhost:8080/CiaoMondoServlet
e vedi un po' che succede!!
Ciao.
Luciano.

dopo aver fatto la prova suggerita da "Mr.Bean"
se ancora non funziona prova a modificare il file web.xml aggiungendo un tag 
simile a :
<servlet>
  <servlet-name> CiaoMondoServlet  </servlet-name>
  <servlet-class> CiaoMondoServlet  </servlet-class>
</servlet> 

Spiego meglio quale è la situazione dopo i suggerimenti:
1) Ho messo i file CiaoMondoservlet.java/.class sotto :
C:\Programmi\Apache Software Foundation\Tomcat 5.5
\webapps\ROOT\WEB-INF\classes
e richiamo :
http://localhost:8080/CiaoMondoServlet
il risultato è il seguente:
The requested resource (/CiaoMondoServlet) is not available
2) il file web.xml l'ho messo sotto
C:\Programmi\Apache Software Foundation\Tomcat 5.5
\webapps\ROOT\WEB-INF
e di seguito mostro il listato:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  Copyright 2004 The Apache Software Foundation
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the 
License.
  You may obtain a copy of the License at
 
http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, 
software
  distributed under the License is distributed on an "AS IS" 
BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 
or implied.
  See the License for the specific language governing 
permissions and
  limitations under the License.
-->
<web-app xmlns="
http://java.sun.com/xml/ns/j2ee
"
    xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance
"
    xsi:schemaLocation="
http://java.sun.com/xml/ns/j2ee
 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
"
    version="2.4">
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
<!-- JSPC servlet mappings start -->
    <servlet>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <servlet-class>org.apache.jsp.index_jsp</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <url-pattern>/index.jsp</url-pattern>
    </servlet-mapping>
 
    <!--QUESTE QUATTRO RIGHE LE HO AGGIUNTE IO -->
    <servlet>
	<servlet-name>CiaoMondoServlet</servlet-name>
	<servlet-class>CiaoMondoServlet</servlet-class>
    </servlet> 
<!-- JSPC servlet mappings end -->


 <!-- JSPC servlet mappings end -->
Aggiungi anche queste righe:
 <servlet-mapping>
  <servlet-name>CiaoMondoServlet</servlet-name>
  <url-pattern>/servlet/CiaoMondoServlet</url-pattern>
 </servlet-mapping> 

 
OK prova a sostituire il file web.xml con questo:
<?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>
	<servlet-mapping>
		<servlet-name>invoker</servlet-name>
		<url-pattern>/servlet/*</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>jsp</servlet-name>
		<url-pattern>*.jsp</url-pattern>
	</servlet-mapping>
</web-app>
in questo caso l'URL per richiamare la servlet sarà:
http://localhost:8080/servlet/CiaoMondoServlet
Ciao.
Luciano.

 ha scritto:

controlla anche che nel file web.xml della tua applicazione
ci sia:
    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
Inviato da 
www.mynewsgate.net


Con Tomcat 5 queste righe danno errore, sono da eliminare.

Sono riuscito a fare funzionare la servlet modificando il file 
web.xml nel seguente modo:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  Copyright 2004 The Apache Software Foundation
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the 
License.
  You may obtain a copy of the License at
 
http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, 
software
  distributed under the License is distributed on an "AS IS" 
BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 
or implied.
  See the License for the specific language governing 
permissions and
  limitations under the License.
-->
<!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>
    <display-name>Servlet 2.4 Examples</display-name>
    <description>
      Servlet 2.4 Examples.
    </description>
    <servlet>
        <servlet-name>CiaoMondoServlet</servlet-name>
        <servlet-class>CiaoMondoServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CiaoMondoServlet</servlet-name>
        <url-pattern>/servlet/CiaoMondoServlet</url-pattern>
    </servlet-mapping>
 
 
 
</web-app>


 
Alleluia!;-)

 ha scritto:

Che strano però...
ho Tomcat 5.5.4 e le righe che ho scritte sono prese pari pari dal file 
web.xml che uso...e funziona benissimo.
Inviato da 
www.mynewsgate.net


Bč io sto usando Tomcat 5.0.28 e se lascio quelle righe il contesto
non parte ed ho questo errore nel log mentre se le elimino tutto funziona
java.lang.reflect.InvocationTargetException
 at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
 at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at 
org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
 at org.apache.commons.digester.CallMethodRule.end(CallMethodRule.java:505)
 at org.apache.commons.digester.Rule.end(Rule.java:276)
 at org.apache.commons.digester.Digester.endElement(Digester.java:1058)
 at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.endNamespaceScope(Unknown 
Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown 
Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
 at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown 
Source)
 at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown 
Source)
 at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 
Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
 at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
 at org.apache.commons.digester.Digester.parse(Digester.java:1548)
 at 
org.apache.catalina.startup.ContextConfig.applicationConfig(ContextConfig.java:263)
 at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:624)
 at 
org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:216)
 at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at 
org.apache.catalina.core.StandardContext.start(StandardContext.java:4290)
 at 
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
 at 
org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)
 at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
 at 
org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:701)
 at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:432)
 at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
 at 
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)
 at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
 at org.apache.catalina.core.StandardService.start(StandardService.java:480)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)
Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an 
unknown servlet name invoker
 at 
org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:2234)
 at 
org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:2214)
 ... 47 more
28-gen-2005 15.29.50 org.apache.catalina.startup.ContextConfig 
applicationConfig
GRAVE: Parse error in application web.xml
java.lang.IllegalArgumentException: Servlet mapping specifies an unknown 
servlet name invoker
 at 
org.apache.commons.digester.Digester.createSAXException(Digester.java:2540)
 at 
org.apache.commons.digester.Digester.createSAXException(Digester.java:2566)
 at org.apache.commons.digester.Digester.endElement(Digester.java:1061)
 at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.endNamespaceScope(Unknown 
Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown 
Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
 at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown 
Source)
 at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown 
Source)
 at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 
Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
 at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
 at org.apache.commons.digester.Digester.parse(Digester.java:1548)
 at 
org.apache.catalina.startup.ContextConfig.applicationConfig(ContextConfig.java:263)
 at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:624)
 at 
org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:216)
 at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at 
org.apache.catalina.core.StandardContext.start(StandardContext.java:4290)
 at 
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
 at 
org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)
 at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
 at 
org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:701)
 at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:432)
 at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
 at 
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)
 at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)
 at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
 at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
 at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
 at org.apache.catalina.core.StandardService.start(StandardService.java:480)
 at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
 at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
 at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

 non parte ed ho questo errore nel log mentre se le elimino tutto funziona
Ho provato al volo con  Tomcat 5.5.4 e mi dà lo stesso errore!


Ecco spiegato, probabilmente tu l'hai abilitato
=========================
Enabling invoker servlet:
=========================
Starting with Tomcat 4.1.12, the invoker servlet is no longer available by
default in all webapps. Enabling it for all webapps is possible by editing
$CATALINA_HOME/conf/web.xml to uncomment the "/servlet/*" servlet-mapping
definition.

servlet name invoker
è la definizione del Servlet a cui il Mapping si riferisce:
in questo caso manca la definizione di Invoker:
 <servlet>
        <servlet-name>invoker</servlet-name>
        <servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
Se non ti funge fammi sapere
che ti mando il mio web.xml
bye.
Inviato da 
www.mynewsgate.net

Rigrazio tutti coloro che mi hanno risposto !!!!!!
GRAZIEEEEEEEEEEEEEEEEEEEEEEEEE


hai riavviato tomcat? 

Ciao,
siccome sto cercando di eseguire una servlet con tomcat, ma pur avendo 
seguito l'intera tua vicenda e avendo provato diverse configurazioni del 
file web.xml, non riesco a farla girare in nessun modo..
Magari mi puoi (potete) dare una mano?
Ho una servlet chiamata SearchManagerServlet, appartenente al package 
webmonitor.web.
L'applicazione si trova nella directory WebMonitorService dentro la 
cartella webapps di Tomcat.
In WebMonitorService ho la pagina html che richiama la servlet e la 
cartella WEB-INF.
Dentro questa, c'è la cartella classes con questa struttura:
classes
    |_webmonitor
             |_web
e dentro web c'è appunto la servlet.
Il mio file web.xml è invece fatto così (aggiornato all'ultima prova che 
ho fatto)
<web-app>
     <display-name>WebMonitor Service</display-name>
     <description>
       Description
     </description>
     <servlet>
        <servlet-name>SearchManagerServlet</servlet-name>
        servlet-class>webmonitor.web.SearchManagerServlet</servlet-class>
     </servlet>
     <servlet-mapping>
       <servlet-name>SearchManagerServlet</servlet-name>
       <url-pattern>/WebmonitorService/SearchManagerServlet</url-pattern>
     </servlet-mapping>
</web-app>
Grazie a tutti,
Jacopo


Prova cosě:
<url-pattern>>/servlet/WebmonitorService/SearchManagerServlet</url-pattern>

 
Ciao,
ho provato come mi hai consigliato, ma purtroppo ottengo ancora l'errore 
  404... resource not available.
Addirittura ho provato anche ad usare la servlet di Gianluca 
(CiaoMondoServlet) e il suo web.xml, con cui lui era riuscito ad 
eseguirla, ma non riesco a far andare nemmeno quella!!
Sono disperato :)

Ho risolto :)
grazie a tutti per l'aiuto
Jacopo

 Jacopo
Sono contento che tu abbia risolto Ieri non ho aperto il 
computer e solo stamattina ho visto i tuoi messaggi.
Scusa....
