Pessoal,
Sou iniciante nesta maravilhosa linguagem e estou com uma dificuldade de iniciante.
NÃO ESTOU CONSEGUINDO FAZER MEUS SERVLETS RODAREM.
Estou colocando abaixo a descrição do que estou fazendo para ver se alguma alma caridosa me ajude.
Estou usando o jdk1.3.1_06, j2sdkee1.3.1e Tomcat 4.0.3
1)No SERVER CONFIGURATION estou adicionando o seguinte contexto :
<!-- testes Context -->
<Context path=“testes” docBase=“testes” debug=“0”
reloadable=“true” crossContext=“true”/>
2)Criei o diretório web-inf na mesma pasta da minha aplicação (root/testes), dentro de web-inf criei a pasta classes.
Na pasta web-inf criei o arquivo web.xml com o seguinte conteúdo :
<?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>
<servlet-name> HelloWorldExample </servlet-name>
<display-name> HelloWorldExample </display-name>
<description> Teste para apresentação de servlet </description>
<servlet-class>servlets. HelloWorldExample </servlet-class>
</servlet>
</web-app>
3)Em seguida aproveitei o arquivo HelloWorldExample da pasta examples, coloquei o .class na pasta /web-inf/classes, o conteudo é o seguinte :
import <a href="http://java.io">java.io</a>.<em>;
import java.text.</em>;
import java.util.<em>;
import javax.servlet.</em>;
import javax.servlet.http.*;
/**
- The simplest possible servlet.
-
@author James Duncan Davidson
*/
public class HelloWorldExample extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
String title = rb.getString("helloworld.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor="white">");
// note that all links are created to be relative. this
// ensures that we can move the web application that this
// servlet belongs to to a different place in the url
// tree and not have any harmful side effects.
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("<a href="/examples/servlets/helloworld.html">");
out.println("<img src="/examples/images/code.gif" height=24 " +
"width=24 align=right border=0 alt="view code"></a>");
out.println("<a href="/examples/servlets/index.html">");
out.println("<img src="/examples/images/return.gif" height=24 " +
"width=24 align=right border=0 alt="return"></a>");
out.println("<h1>" + title + "</h1>");
out.println("legal, funciona!!!!");
out.println("</body>");
out.println("</html>");
}
}
4)criei um arquivo HTML e fiz a chamada para a servlet da seguinte maneira :
<a href="…/servlet/HelloWorldExample"
POR FAVOR, O QUE É QUE ESTOU FAZENDO DE ERRADO ?
Espero que alguém me ajude.
Um abraço,
