0
我在寫jsp-servlet應用程序並獲取405 http狀態。我在尋找很長一段時間,但我不明白我做錯了什麼。HTTP狀態405 - 此URL不支持HTTP方法GET
我的應用程序服務器是Apache Tomcat-7.0.25。
我的JSP頁前進
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
<jsp:forward page="/myservlet" />
</body>
</html>
我的servlet
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>
什麼可以是這個原因,我怎麼能解決這個問題?你有任何假設嗎?