各位先進前輩們大家好
以下是一個基礎範例
我的疑問是為什麼程式碼中的goGet可以順利執行,但改成doPost後在執行時會跳出錯誤訊息405,HelloWorld不是已經繼承了HttpServlet類別的doGet()跟doPost()方法嗎?
// Import required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
// Set response content type
res.setContentType("text/html");
// Actual logic goes here.
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello World!</BIG>");
out.println("</BODY></HTML>");
}
}