HTTP Status 405 - HTTP method GET is not supported by this URL

6 respostas
mazinhospinter

Pessoal treinando em java e me deparei com este erro que fazer?
HTTP Status 405 - HTTP method GET is not supported by this URL

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).
Apache Tomcat/6.0.14

Soma.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author ti_gilcimar
 */
public class Soma extends HttpServlet {
    
    Vector v = new Vector(5);
    protected void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException,java.io.IOException{
        v.clear();
        Enumeration e = req.getParameterNames();
        
        while(e.hasMoreElements()) {
            String name = (String)e.nextElement();
            String value = req.getParameter(name);
            if(value !=null)v.add(value);
        }
        
       res.setContentType("text/html");
       java.io.PrintWriter out = res.getWriter();
       out.println("<html>");
       out.println("<head><title>Servlet</title></head>");
       out.println("<body>");
       out.println("<h1>A Soma e:");
       int soma = 0;
        for(int i=0; i<v.size();i++){
            soma += Integer.parseInt((String)v.get(i));
        }
        out.println(soma);
        out.println("<h1>");
        out.println("</body>");
        out.println("</html>");
        out.close();
}
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.validateXml</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.verifyObjects</param-name>
        <param-value>false</param-value>
    </context-param>
    <filter>
        <filter-name>UploadFilter</filter-name>
        <filter-class>com.sun.webui.jsf.util.UploadFilter</filter-class>
        <init-param>
            <description>The maximum allowed upload size in bytes.  If this is set to a negative value, there is no maximum.  The default value is 1000000.</description>
            <param-name>maxSize</param-name>
            <param-value>1000000</param-value>
        </init-param>
        <init-param>
            <description>The size (in bytes) of an uploaded file which, if it is exceeded, will cause the file to be written directly to disk instead of stored in memory.  Files smaller than or equal to this size will be stored in memory.  The default value is 4096.</description>
            <param-name>sizeThreshold</param-name>
            <param-value>4096</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>UploadFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <init-param>
            <param-name>javax.faces.LIFECYCLE_ID</param-name>
            <param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>ExceptionHandlerServlet</servlet-name>
        <servlet-class>com.sun.errorhandler.ExceptionHandler</servlet-class>
        <init-param>
            <param-name>errorHost</param-name>
            <param-value>localhost</param-value>
        </init-param>
        <init-param>
            <param-name>errorPort</param-name>
            <param-value>24444</param-value>
        </init-param>
    </servlet>
    <servlet>
        <servlet-name>ThemeServlet</servlet-name>
        <servlet-class>com.sun.webui.theme.ThemeServlet</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>Soma</servlet-name>
        <servlet-class>Soma</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ExceptionHandlerServlet</servlet-name>
        <url-pattern>/error/ExceptionHandler</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ThemeServlet</servlet-name>
        <url-pattern>/theme/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Soma</servlet-name>
        <url-pattern>/Soma</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/Page1.jsp</welcome-file>
        </welcome-file-list>
    <error-page>
        <exception-type>javax.servlet.ServletException</exception-type>
        <location>/error/ExceptionHandler</location>
    </error-page>
    <error-page>
        <exception-type>java.io.IOException</exception-type>
        <location>/error/ExceptionHandler</location>
    </error-page>
    <error-page>
        <exception-type>javax.faces.FacesException</exception-type>
        <location>/error/ExceptionHandler</location>
    </error-page>
    <error-page>
        <exception-type>com.sun.rave.web.ui.appbase.ApplicationException</exception-type>
        <location>/error/ExceptionHandler</location>
    </error-page>
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jspf</url-pattern>
            <is-xml>true</is-xml>
        </jsp-property-group>
        </jsp-config>
    </web-app>

6 Respostas

von.juliano
No seu jsp vc deve ter especificado para chamar o método get, e como vc não o criou ele apresenta esse problema. Para resolver, vc pode alterar o form no seu jsp assim:
<form action="..." method="get">
ou incluir o seguinte no seu servlet:
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	doPost(request, response);
}
Blz? Flw! :thumbup:
Mauricio_Linhares

Não dá pra fazer upload de arquivos usando GET, upload tem que ser feito com POST. Altere o seu formulário pra fazer POST e coloque o mais um atributo nele, deve ficar assim:

<form method="post" enctype="multipart/form-data">
</form>
jgbt
corrigindo:
von.juliano:
No seu jsp vc deve ter especificado para chamar o método get, e como vc não o criou ele apresenta esse problema. Para resolver, vc pode alterar o form no seu jsp assim:
<form action="..." method="post">
ou incluir o seguinte no seu servlet:
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	doPost(request, response);
}
Blz? Flw! :thumbup:

[]´s

von.juliano

jgbt:
corrigindo:

Hehe, pequena falha! :XD: Vlw!

mazinhospinter

Galera deu certo…

mazinhospinter

******** RESOLVIDO ********

Criado 23 de janeiro de 2008
Ultima resposta 29 de jan. de 2008
Respostas 6
Participantes 4