Tomcat的Servlet的:错误404 - 请求的资源不可用 [英] Tomcat Servlet: Error 404 - The requested resource is not available

查看:9968
本文介绍了Tomcat的Servlet的:错误404 - 请求的资源不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是完全新的编写Java Servlet的,和我挣扎着爬一个简单的的HelloWorld 例如正常工作。

I am completely new to writing a Java Servlet, and am struggling to get a simple HelloWorld example to work properly.

HelloWorld.java类是:

The HelloWorld.java class is:

package crunch;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Hello World");
  }
}

我Tomcat运行V7.0,并且已经阅读类似的问题,有指改变响应调用 Servlet映射的web.xml C $ C>部分,这一部分其实并不在我的存在,当我加入这同样的问题仍时有发生。

I am running Tomcat v7.0, and have already read similar questions, with responses referring to changing the invoker servlet-mapping section in web.xml, this section actually doesn't exist in mine, and when I added it the same problem still occurred.

推荐答案

试试这个(如果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

这篇关于Tomcat的Servlet的:错误404 - 请求的资源不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆