且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Tomcat的Servlet的:错误404 - 请求的资源不可用

更新时间:2022-03-18 23:17:20

试试这个(如果Java EE V6)

try this (if the Java EE V6)

package crunch;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
@WebServlet(name="hello",urlPatterns={"/hello"})
public class HelloWorld extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Hello World");
  }
}

现在达到通过 http://127.0.0.1:8080/yourapp/hello

其中8080​​为默认的Tomcat端口,yourapp是你applciation的上下文名称

where 8080 is default tomcat port, and yourapp is the context name of your applciation