HTTP status 405 - HTTP method POST is not supported by this URL

Posted by Wont Say on Stack Overflow See other posts from Stack Overflow or by Wont Say
Published on 2012-06-27T08:58:03Z Indexed on 2012/06/27 9:15 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

I am getting this "HTTP method POST is not supported by this URL" error when I run my project. The funny thing is, it was running perfectly fine two days ago. After I made a few changes to my code but then restored my original code and its giving me this error. Could you please help me?

Here is my index.html:

<form method="post" action="login.do">
<div>
<table>
            <tr><td>Username: </td><td><input type="text" name="e_name"/>
            </td>  </tr>
            <tr><td> Password: </td><td><input type="password" name="e_pass"/>
            </td>  </tr>
            <tr><td></td><td><input type="submit" name ="e_submit" value="Submit"/>

Here is my Login servlet:

public class Login extends HttpServlet {

/**
 * Processes requests for both HTTP
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        /*
         * TODO output your page here. You may use following sample code.
         */
        int status;
        String submit = request.getParameter("e_submit");
        String submit2 = request.getParameter("a_submit");
        out.println("Here1");
        String e_name = request.getParameter("e_name");
        String e_password = request.getParameter("e_pass");
        String a_name = request.getParameter("a_name");
        String a_password = request.getParameter("a_pass");
        out.println(e_name+e_password+a_name+a_password);
        Author author = new Author(a_name,a_password);  
        Editor editor = new Editor(e_name,e_password);

      // If it is an AUTHOR login:

       if(submit==null){
       status = author.login(author);
       out.println("Author Login");
       //Incorrect login details
       if(status==0) {
           out.println("Incorrect");

       RequestDispatcher view = request.getRequestDispatcher("index_F.html");
       view.forward(request, response);

       }
       //Correct login details --- AUTHOR

       else {

              out.println("Correct login details");
              HttpSession session = request.getSession();    
              session.setAttribute(a_name, "a_name");

              RequestDispatcher view = request.getRequestDispatcher("index_S.jsp"); 
              view.forward(request, response);
            }

       }

       //If it is an EDITOR login

       else if (submit2==null){

           status = editor.login(editor);

           //Incorrect login details

           if(status==0) {

       RequestDispatcher view = request.getRequestDispatcher("index_F.html");
       view.forward(request, response);
            }

           //Correct login details --- EDITOR

           else {
               out.println("correct");
               HttpSession session = request.getSession();    
       session.setAttribute(e_name, "e_name");
       session.setAttribute(e_password, "e_pass");
               RequestDispatcher view   = request.getRequestDispatcher("index_S_1.html"); 
               view.forward(request, response);

            }           }


        out.println("</body>");
        out.println("</html>");



    } finally {            
        out.close();
    }
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    super.doPost(req, resp);
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    super.doGet(req, resp);
}}

And my web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
        <param-name>debug</param-name>
        <param-value>2</param-value>
    </init-param>
    <init-param>
        <param-name>detail</param-name>
        <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet>
    <servlet-name>Login</servlet-name>
    <servlet-class>controller.Login</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Login</servlet-name>

    <url-pattern>/login.do</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

I use Glassfish v3 server - let me know anything else you need to know

© Stack Overflow or respective owner

Related posts about java

Related posts about http