【问题标题】:The requested resource is not available for servlet 3.0 and tomcat 7.0请求的资源不适用于 servlet 3.0 和 tomcat 7.0
【发布时间】:2013-06-01 01:18:12
【问题描述】:

我的动态web模块版本是3.0,tomcat我的tomcat版本是7.0

我不知道为什么当我导航到页面 localhost:8080/SimpleProject 时它看不到我的 servlet XD。

当我导航到 localhost:8080/SimpleProject/firstservlet 时,我收到一条错误消息,上面写着 the requested resource is not available!

这是我的 servlet:

@WebServlet(description = "the first servlet", urlPatterns = { "/firstservlet" })
public class FirstServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//   response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.println("<h1>Why can't See<h1>");
}

我没有在 web.xml 上做任何事情,因为我知道在 3.0 版本中,url 映射在 servlet 中。

这是我的文件安排 :)

【问题讨论】:

  • 您的上下文(根路径)是您的战争名称(以“.war”结尾),除非您在 context.xml 文件中专门将其设置为其他内容。
  • 你能分享你的 web.xml 吗?
  • @ShadowCreeper 我已经这样做了。仍然请求的资源不可用
  • @F.H.当你将一个 html 文件放在你的战争的根目录中时,你能用你的浏览器点击它吗? http://localhost:8080/SimpleProject/index.html 例如?
  • @ShadowCreeper 是的,我做到了...

标签: java


【解决方案1】:

您是否检查了日志文件以查看在加载/执行您的 servlet FirstServlet 时是否引发了一些异常?

您是否检查了您的 war 文件的内容以确保它被正确打包并且 servlet 类在其中(您可以像打开一个 zip 文件一样打开一个 war 文件)。

【讨论】:

    猜你喜欢
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多