首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tomcat请求的资源()不可用

问tomcat请求的资源()不可用
EN

Stack Overflow用户
提问于 2011-02-21 14:38:22
回答 3查看 84.9K关注 0票数 12

我知道这是一个非常常见的问题,因为我在几个论坛上发现了许多与此相关的问题,包括。但是我还没有找到解决方案,我的web.xml (位于WEB-INF)

代码语言:javascript
复制
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>SMSProjectNew</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>ReceiveMessagesServlet</display-name>
    <servlet-name>ReceiveMessagesServlet</servlet-name>
    <servlet-class>com.sendreceive.ReceiveMessagesServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ReceiveMessagesServlet</servlet-name>
    <url-pattern>/ReceiveMessagesServlet</url-pattern>
  </servlet-mapping>
</web-app>

位于WebContent文件夹中的html页面index.html

代码语言:javascript
复制
<!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>
The application started successfully version 1:27
<form action="/ReceiveMessagesServlet" method="post">
<input type="text" name="number"/>
<input type="text" name="message"/>
<input type="submit" name="submit"/>
</form> 
</body>
</html>

最后是位于src\com.sendreceive包com.sendreceive中的servlet ReceiveMessagesServlet;

代码语言:javascript
复制
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

   public class ReceiveMessagesServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public ReceiveMessagesServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request,response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request,response);
    }

    protected void processRequest(HttpServletRequest request,
            HttpServletResponse response) {
        String responseMessage = request.getParameter("message");
        String responseNumber = request.getParameter("number");
        System.out.println(responseMessage+responseNumber);
    }

}

我已经在eclipse中安装了tomcat插件。当我右键点击项目,然后点击run the project on server。tomcat服务器在eclipse中启动,index.html页面为shown..but。当我在字段中输入一些值并单击submit..it时,会出现404错误。..我一直在从过去的2个hours..kindly help..also..fyi中挣扎,我正在使用本教程http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/index.html

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-02-21 17:16:41

由于action="/ReceiveMessagesServlet",您将收到404错误,请删除斜杠。尝试使用action="ReceiveMessagesServlet“。

当你在URL模式中添加一个斜杠时,容器将查找一个部署了名为‘ReceiveMessagesServlet’的web应用程序。因为这不存在,你将收到404错误。

票数 13
EN

Stack Overflow用户

发布于 2011-02-21 16:27:15

当您将您的应用程序部署到servlet容器中时,您的URL可能会在该容器中的其他应用程序中标识您的应用程序的上下文路径作为前缀(即/ReceiveMessagesServlet变为/MyApp/ReceiveMessagesServlet)。

因此,您应该考虑到这种可能性,并相应地修改您的URL,例如,使用JSTL的<c:url>

代码语言:javascript
复制
<form action="<c:url = value = '/ReceiveMessagesServlet' />" method="post"> 

或者,在没有JSTL的情况下:

代码语言:javascript
复制
<form action="${pageContext.request.contextPath}/ReceiveMessagesServlet" method="post"> 
票数 7
EN

Stack Overflow用户

发布于 2013-02-07 00:02:58

servlet中的错误可能会导致Tomcat将其标记为不可用,就像我在服务器日志中得到的那样:

06/02/2013 13:32:43 org.apache.catalina.core.ApplicationContext日志信息:将servlet成像器标记为不可用6/02/2013 13:32:43 org.apache.catalina.core.StandardWrapperValve调用严重:为servlet成像器java.lang.ClassNotFoundException com.project.test.ImageThumber分配异常

您应该查看日志中的原因。在我的例子中,缺少一些测试类的jar。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5063044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档