how create simple(servelet) java ee project in eclipse and tomcat
I'm open to
eclipse --> new --> dynamic web project --> in target runtime --> new Apache Tomcat v6.0 and establish mark Create a new local server --> next Browse establish way C:\dev\apache-tomcat-6.0.29-windows-x86\apache-tomcat-6.0.29 --> finish --> in new dynamic project finish
in Java Resources : src new class
java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class f extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
resp.setContentType("text/html开发者_如何学Go;charset=utf-8");
PrintWriter pw = resp.getWriter();
pw.println("<H1>Hello, world! или Привет мир</H1>");
}
}
-->server start in save resources s.java been modified. Save changes? I'm yes. --> Run servlet/s --> result HTTP Status 404 - /s/servlet/s
type Status report
message /s/servlet/s
description The requested resource (/s/servlet/s) is not available.
Apache Tomcat/6.0.14
How and when I'm error? How need the create right?
I'm sorry, bad English. explain most clear and distinctly
Have you checked the web.xml
deployment descriptor?
There you have to define your servlet mapping, or otherwise the servlet container won't have notice of the servlet.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Servlet definition -->
<servlet>
<servlet-name>s</servlet-name>
<servlet-class>your.package.path.s</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
<servlet-name>s</servlet-name>
<url-pattern>/myServlet</url-pattern>
</servlet-mapping>
<web-app>
And now, you can access it with your mapped path ("/<contextPath>/myServlet
") or with the default invoker ("/<contextPath>/servlet/s
").
精彩评论