Não sei como rodar um servlet fora do eclipse.
Tenho a classe java:
public class MeuServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -3696684582280279984L;
/**
* @see HttpServlet#HttpServlet()
*/
public MeuServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processo(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processo(request, response);
}
private void processo(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher rd = request
.getRequestDispatcher("/contato-adicionado.jsp");
rd.forward(request, response);
}
}
Dentro da pasta WebContent tenho a pasra WEB-INF e dentro desta
tenho o arquivo xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>MeuPrimeiroServlet</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>MeuServlet</display-name>
<servlet-name>MeuServlet</servlet-name>
<servlet-class>br.com.alex.MeuServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MeuServlet</servlet-name>
<url-pattern>/MeuServlet</url-pattern>
</servlet-mapping>
</web-app>
Ainda dentro da pasta WebContent
tenho o arquivo contato-adicionado.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Sandro Alex Fernandes Ferandes</h1>
</body>
</html>
Quando o tomcat esta startado no eclipse, basta em um navegador eu digitar:
http://localhost:8080/MeuPrimeiroServlet/MeuServlet
(porta/nome do meu projeto/nome da minha classe que é mapeada no web.xml)
e tudo OK.
Gostaria de saber dos “Jedais” como rotar fora do eclipse, e mais, como testar esta minha mini aplicação em outro computador (o que precisa fazer/ter no outro computador)? Desde ja agradeço.