Tomcat erro: HTTP Status 404 ?!?!?!

Oi gente!!

Bem, isntalei o tomcat bem bonitinho, como manda o protocolo…

so tem um problema.
Meus servlets nao aparecem de jeito nenhum!!

criei uma pasta dentro de webapps, o nome da pasta é ticianne.
dentro da minha pasta criei uma WEB-INF, dentro da web-inf, criei classes e lib. coloquei meu arquivo .java e .class dentro da pasta classes.

olha so o erro que da quando tento acessar assim:

http://localhost:8080/ticianne/servlet/zzz

ERRO:

HTTP Status 404 - /ticianne/servlet/zzz

type Status report

message /ticianne/servlet/zzz

description The requested resource (/ticianne/servlet/zzz) is not available.
Apache Tomcat/5.5.17

Esse é o codigo do servlet:

[code]import javax.servlet.http.*;

public class zzz extends HttpServlet{

public void doGet(HttpServletRequest req, HttpServletResponse res){
	
}

}
[/code]

como é so para teste, so fiz isso mesmo, as era pra aparecer uma pagina em branco, nao??

bem, arquivos html aparecem direitinho, so ta dando problema com meus servlets. os que vieram como exempo do tomcat tao beleza, funcionam perfeitamente.

Alguem pode dar uma luz aqui?? :smiley: :smiley: :smiley:

vc declarou/mapeou o servlet no web.xml ???

Vc mapeou essa servlet no arquivo web.xml?

Segue um exemplo:

<web-app>
	
	<display-name>Bolão da Copa 2006</display-name>
	
	<servlet>
		<servlet-name>bolao</servlet-name>
		<servlet-class>br.com.pedrosa.action.BolaoAction</servlet-class>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>bolao</servlet-name>
			<url-pattern>/bolao</url-pattern>
	</servlet-mapping>

	
	<session-config>
		<session-timeout>30</session-timeout>
	</session-config>

	<welcome-file-list>
		  <welcome-file>Index.jsp</welcome-file>
		  <welcome-file>Index.htm</welcome-file>
	</welcome-file-list>
	
	<error-page>
		<exception-type>java.lang.Exception</exception-type>
		<location>/erro.jsp</location>
	</error-page>
 
</web-app>

espera…

eu tenho que acrescentar tudo isso ao web.xml???

e devo fazer isso pra cada servlet que for rodar?

mas…

serio mesmo??? :shock:

so uma pergunta, vc instalou como o Tomcat:

  • zip
  • ou exe

?

foi o .exe 5.5.17

Ai ai ai ai Ticianne !!!

O Duke vai ficar brabo com você!!

Tem que seguir umas regrinhas senão não vai dar liga na salada !!

Se você não mapear os servlets no web.xml, nada feito…

[quote=Ticianne]espera…

eu tenho que acrescentar tudo isso ao web.xml???

e devo fazer isso pra cada servlet que for rodar?

mas…

serio mesmo??? :shock: [/quote]

Não tudo isso para cada servlet, mas isso sim (usando o exemplo do golega acima):


<servlet-name>bolao</servlet-name>
 		<servlet-class>br.com.pedrosa.action.BolaoAction</servlet-class>
 	</servlet>
 	
 	<servlet-mapping>
 		<servlet-name>bolao</servlet-name>
 			<url-pattern>/bolao</url-pattern>
 	</servlet-mapping>

uma tag e outra para cada servlet seu, senão sua página não vai ser encontrada.

minha pergunta pareceu meio vaga, mas na verdade ja tive problemas usando a zipada.

Vc ta usando o Eclipse pra criar seu projeto Web?
Vc ta integrando o tomcat com o eclipse?
Se nao me engano quando vc cria um projeto web dinamico
ele ja cria p web.xml básico.

1- Quem é Duke?

2- Mas pq eu preciso mapear? mesmo tendo instalado pelo exe?

3- Meu livro diz que devia funcionar so assim… :frowning:

Olha a heresia menina :stuck_out_tongue:

[quote=Ticianne]espera…

eu tenho que acrescentar tudo isso ao web.xml???

e devo fazer isso pra cada servlet que for rodar?

mas…

serio mesmo??? :shock: [/quote]

Para cada servlet vc deve mapear em:

<servlet>
  <servlet-name>bolao</servlet-name>
  <servlet-class>br.com.pedrosa.action.BolaoAction</servlet-class>
</servlet>
 	
<servlet-mapping>
  <servlet-name>bolao</servlet-name>
  <url-pattern>/bolao</url-pattern>
</servlet-mapping>

Aqui é o tempo da sessão

<session-config>
   <session-timeout>30</session-timeout>
</session-config>

Sua página inicial

<welcome-file-list>
  <welcome-file>Index.jsp</welcome-file>
  <welcome-file>Index.htm</welcome-file>
</welcome-file-list>

Direcionar para página de erro:

<error-page>
  <exception-type>java.lang.Exception</exception-type>
   <location>/erro.jsp</location>
</error-page>

Eu to usando o eclipse mas nao integrei como tomcat. como posso fazer isso? me parece mais interessante do que acrescentar as tags toda vida que fizer um servlet…

:slight_smile:

certo… e se eu for fazer isso manualmente mesmo… em que parte do web.xml eu acrescento esse dados?

na tag eu devo botar o nome da classe principal do meu arquivo .java?
em devo colocar a pasta raiz do servlet ou todo o endereço?

Existe o plugin Sysdeo do Eclipse:

http://www.sysdeo.com/eclipse/tomcatplugin

aqui vc da start, stop, reload etç, e vc pode configurar um arquivo no Tomcat apontando para seu workspace e atualizando automaticamente

em C:\jakarta-tomcat-5.5.xx\conf\Catalina\localhost ou onde se encontrar, crie um arquivo xml com o nome do seu sistema com o seguinte conteúdo:

<Context path="/nomeSite" docBase="caminhoDaAplicação" debug="0" reloadable="true">

Sim, deve colocar o caminho completo da sua Servlet e no url equivale ao link para a servlet dentro da sua aplicação.

heheh

desculpa a minha ignorancia, mas… quando vc diz um arquivo com o nome do meu sistema quer dizer windows.xml??

em que parte do web.xml eu devo acrescentar essas tags?? qualquer lugar mesmo???

aqui esta meu web.xml:

<?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>


    <!-- General description of your web application -->

    <display-name>My Web Application</display-name>
    <description>
      This is version X.X of an application to perform
      a wild and wonderful task, based on servlets and
      JSP pages.  It was written by Dave Developer
      (dave@mycompany.com), who should be contacted for
      more information.
    </description>


    <!-- Context initialization parameters that define shared
         String constants used within your application, which
         can be customized by the system administrator who is
         installing your application.  The values actually
         assigned to these parameters can be retrieved in a
         servlet or JSP page by calling:

             String value =
               getServletContext().getInitParameter("name");

         where "name" matches the <param-name> element of
         one of these initialization parameters.

         You can define any number of context initialization
         parameters, including zero.
    -->

    <context-param>
      <param-name>webmaster</param-name>
      <param-value>myaddress@mycompany.com</param-value>
      <description>
        The EMAIL address of the administrator to whom questions
        and comments about this application should be addressed.
      </description>
    </context-param>


    <!-- Servlet definitions for the servlets that make up
         your web application, including initialization
         parameters.  With Tomcat, you can also send requests
         to servlets not listed here with a request like this:

           http://localhost:8080/{context-path}/servlet/{classname}

         but this usage is not guaranteed to be portable.  It also
         makes relative references to images and other resources
         required by your servlet more complicated, so defining
         all of your servlets (and defining a mapping to them with
         a servlet-mapping element) is recommended.

         Servlet initialization parameters can be retrieved in a
         servlet or JSP page by calling:

             String value =
               getServletConfig().getInitParameter("name");

         where "name" matches the <param-name> element of
         one of these initialization parameters.

         You can define any number of servlets, including zero.
    -->

    <servlet>
      <servlet-name>controller</servlet-name>
      <description>
        This servlet plays the "controller" role in the MVC architecture
        used in this application.  It is generally mapped to the ".do"
        filename extension with a servlet-mapping element, and all form
        submits in the app will be submitted to a request URI like
        "saveCustomer.do", which will therefore be mapped to this servlet.

        The initialization parameter namess for this servlet are the
        "servlet path" that will be received by this servlet (after the
        filename extension is removed).  The corresponding value is the
        name of the action class that will be used to process this request.
      </description>
      <servlet-class>com.mycompany.mypackage.ControllerServlet</servlet-class>
      <init-param>
        <param-name>listOrders</param-name>
        <param-value>com.mycompany.myactions.ListOrdersAction</param-value>
      </init-param>
      <init-param>
        <param-name>saveCustomer</param-name>
        <param-value>com.mycompany.myactions.SaveCustomerAction</param-value>
      </init-param>
      <!-- Load this servlet at server startup time -->
      <load-on-startup>5</load-on-startup>
    </servlet>

    <servlet>
      <servlet-name>graph</servlet-name>
      <description>
        This servlet produces GIF images that are dynamically generated
        graphs, based on the input parameters included on the request.
        It is generally mapped to a specific request URI like "/graph".
      </description>
    </servlet>


    <!-- Define mappings that are used by the servlet container to
         translate a particular request URI (context-relative) to a
         particular servlet.  The examples below correspond to the
         servlet descriptions above.  Thus, a request URI like:

           http://localhost:8080/{contextpath}/graph

         will be mapped to the "graph" servlet, while a request like:

           http://localhost:8080/{contextpath}/saveCustomer.do

         will be mapped to the "controller" servlet.

         You may define any number of servlet mappings, including zero.
         It is also legal to define more than one mapping for the same
         servlet, if you wish to.
    -->

    <servlet-mapping>
      <servlet-name>controller</servlet-name>
      <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
      <servlet-name>graph</servlet-name>
      <url-pattern>/graph</url-pattern>
    </servlet-mapping>


    <!-- Define the default session timeout for your application,
         in minutes.  From a servlet or JSP page, you can modify
         the timeout for a particular session dynamically by using
         HttpSession.getMaxInactiveInterval(). -->

    <session-config>
      <session-timeout>30</session-timeout>    <!-- 30 minutes -->
    </session-config>


</web-app>