简体   繁体   English

为什么我收到“此 URL 不支持 HTTP 方法 GET”错误?

[英]Why I am getting 'HTTP method GET is not supported by this URL' error?

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet
{
private void sendLoginPage (HttpServletResponse res, HttpServletRequest req, boolean error)
throws ServletException,IOException
{
    res.setContentType("text/html");
    PrintWriter o = res.getWriter();        
    o.println("<html><head><title>Sample Login Page</title></head><body>Welcome to Login Page : ");
    if (error)
    o.println("<fieldset><legend>Login Form : </legend>");
    o.println("Login Failed, Please Try Again");
    o.println("<form method="+"post"+">");
    o.println("<br/><input type="+"text"+"value="+"username"+"/>");
    o.println("<br/><input type="+"password"+"value="+""+"/>");
    o.println("<br/><input type="+"button"+"value="+"Submit"+"/>");
    o.println("</form></fieldset></body></html>");
}

public void doGet (HttpServletResponse res, HttpServletRequest req)
throws ServletException,IOException
{
    sendLoginPage ( res, null, false ) ;
}

public void doPost (HttpServletResponse res, HttpServletRequest req)
throws ServletException,IOException
{
    String username = req.getParameter("username");
    String password = req.getParameter("password");
    if ( username.equals("*******") && password.equals("*******") )
    {
        res.sendRedirect ("http://localhost:7001/ten/r1");
    }
    else 
    {
        sendLoginPage ( res, null, true ) ;
    }
}           
}                   

Well this Servlet compiles okay without any errors and also gets deployed on the server but shows this error when trying to access it through url:好吧,这个 Servlet 编译正常,没有任何错误,并且也部署在服务器上,但在尝试通过 url 访问它时显示此错误:

HTTP method GET is not supported by this URL此 URL 不支持 HTTP 方法 GET

You have the HttpServletResponse and HttpServletRequest parameters reversed on your methods.您在方法上颠倒了 HttpServletResponse 和 HttpServletRequest 参数。

Side note: Using the @Override annotation on overridden methods would cause a compile error for this (assuming you're using at least Java 1.5)旁注:在重写方法上使用@Override 注释导致编译错误(假设您至少使用 Java 1.5)

This happened to me when my method call当我的方法调用时发生在我身上

"super.doGet(req, resp)" or "super.doPost(req, resp)". “super.doGet(req, resp)”或“super.doPost(req, resp)”。

After i removed above super class calling from the doGet and doPost it worked fine.在我删除了从 doGet 和 doPost 调用的超级 class 之后,它工作正常。

Infact those super class calling codes were inserted by the Eclipse IDE template.事实上,那些超级 class 调用代码是由 Eclipse IDE 模板插入的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在此代码中的任何地方都没有使用此URL不支持的错误HTTP GET方法 - Why I am getting error HTTP GET method not supported by this URL, while I am not using it anywhere in my code 我是jsp和google app引擎的新手,但出现此错误:此URL不支持HTTP方法GET。 - I am new to jsp and google app engine getting this error: HTTP method GET is not supported by this URL 不支持请求方法“GET”。 为什么我会收到此错误? - Request method 'GET' not supported. Why am I getting this error? 为什么会出现错误“此URL不支持HTTP方法发布”? - Why I got the error “HTTP method post is not supported by this URL”? 获取错误HTTP状态405 - 此方法不支持HTTP方法GET但不使用`get`? - getting error HTTP Status 405 - HTTP method GET is not supported by this URL but not used `get` ever? 当我尝试连接到URL时,为什么会收到“HTTP版本不支持”的回复? - Why am I getting 'HTTP Version Not Supported' reply when I try to connect to a URL? HTTP状态405-此URL不支持HTTP方法GET-RequestDispatcher出现错误 - HTTP Status 405 - HTTP method GET is not supported by this URL - getting error with RequestDispatcher 出现错误“此URL不支持消息HTTP方法GET”,但从未在任何地方使用GET - Getting error “Message HTTP method GET is not supported by this URL” but never used GET anywhere Tomcat错误HTTP状态405-此URL不支持HTTP方法GET - Tomcat error HTTP Status 405 - HTTP method GET is not supported by this URL 错误原因:HTTP状态405-此URL不支持HTTP方法GET - Reason for error : HTTP Status 405 - HTTP method GET is not supported by this URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM