我正在编写 jsp-servlet 应用程序并获得 405 http-status。我找了很长时间,但我不明白我做错了什么。
我的应用服务器是 Apache Tomcat-7.0.25。
我的 JSP 转发页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<jsp:forward page="/myservlet" />
</body>
</html>
我的小服务程序
public class MyServlet extends HttpServlet {
private static final String url = "http://ibm.com";
public void doGet(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
URLConnection conn = null;
URL connectURL = null;
try {
PrintWriter out = response.getWriter();
connectURL = new URL(url);
conn = connectURL.openConnection();
DataInputStream theHTML = new DataInputStream(conn.getInputStream());
String thisLine;
while ((thisLine = theHTML.readLine()) != null) {
out.println(thisLine);
}
out.flush();
out.close();
} catch (Exception e) {
System.out.println("Exception in MyServlet: " + e.getMessage());
e.printStackTrace();
}
}
}
我的部署描述符 (web.xml) 文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>My web application</display-name>
<description>My servet application</description>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这可能是什么原因,我该如何解决这个问题?你有什么假设吗?