Tomcat 7 在调用静态页面时给出 HTTP 405

标签 tomcat

我使用 eclipse IDE 创建了一个动态项目。我在 CollegeManagement 项目的 WebContent 文件夹中添加了一个 html 页面 Welcome.html。我在 Apache Tomcat-7.0.47 上部署了该项目。部署后,我可以在 C:\apache-tomcat-7.0.47\webapps 中看到一个文件夹 CollegeManagement,其中包含 Welcome.html。当我通过右键单击 Welcome.html 并选择在服务器上运行来运行应用程序时,出现错误 HTTP 405。有人可以帮我解决这个问题吗?请在此处找到快照 http://imageshack.us/photo/my-images/843/3q0r.png/

项目结构图:http://imageshack.us/photo/my-images/826/ufep.png/

HTML 页面 Welcome.html 包含

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Welcome</title>
</head>
<body>
<form method="post" action="http://localhost:8181/CollegeManagement/do">
Operation<input type="text" name="op"/>
<button type="submit">Do</button>
</form>
</body>
</html>

web.xml 包含

<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>CollegeManagement</display-name>
  <welcome-file-list>
   <!--  <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file> -->
     <welcome-file></welcome-file>
  </welcome-file-list>

  <servlet-mapping>
  <servlet-name>welcome</servlet-name>
  <url-pattern>/*</url-pattern>
  </servlet-mapping>
  <servlet>
  <servlet-name>welcome</servlet-name>
  <servlet-class>com.vijay.Welcome</servlet-class>
  </servlet>
</web-app>

我正在尝试访问服务器上的静态页面,它应该在不检查 web.xml 或 HTML 文件内容的情况下返回。为什么不支持返回 GET 方法?

仅供引用:我已尝试将 Welcome.html 重命名为 College.html,问题仍然存在。

非常感谢。

最佳答案

注意:首先检查是否有错误的url-pattern。

使用以下内容确保默认的 servlet 容器。

  <!-- Disables Servlet Container welcome file handling. Needed for compatibility with Servlet 3.0 and Tomcat 7.0 -->
  <welcome-file-list>
    <welcome-file></welcome-file>
  </welcome-file-list>

这是因为您可能在没有实际实现 doGet() 的情况下调用 doGet()。 doGet() 的默认实现会引发错误,指出该方法不受支持。

关于Tomcat 7 在调用静态页面时给出 HTTP 405,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19768593/

相关文章:

java - F5 规则与 RESTful 服务

java - tomcat/servlet 中的并发

java - tomcat正常运行一段时间后挂掉

java - Spring中如何使用Tomcat提供的JNDI DataSource?

apache - 负载测试我们的 Web 应用程序时出现奇怪的 Jersey 异常

gwt - 文件路径 gwt 应用程序托管模式

java - Spring MVC 无法解析 View 名称

java - HttpServlet 是单例吗?

spring-boot - 使用 Logback MDC 进行 Spring Boot ErrorController 日志记录

maven - 在 tomcat7-maven-plugin 目标中使用 "provided"类路径