Olá pessoal, estou começando minhas pesquisas com java, e me deparei com o erro 405 ao usar um servlet ...
aki é minha pagina JSP:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Primeiro Teste Somando Numeros</h1>
<input type="text" name="txtValor" value="" size="10" id="txtValor" />
<input type="button" value="OK" name="btnOk" onclick="enviar()" />
<input type="text" name="txtResultado" value="" size="40" id="txtResultado" />
</body>
</html>
<script>
var req;
function enviar(){
var valor = document.getElementById("txtValor").value;
var url = "response";
req = new XMLHttpRequest();
req.open("get",url,true);
req.onreadystatechange = callback;
req.send(null);
}
function callback(){
if(req.readyState == 4){
if(req.status == 200){
document.getElementById("txtResultado").value = req.responseText;
}
if(req.status == 404){
document.getElementById("txtResultado").value = "não achou a pagina";
}
if(req.status == 405){
document.getElementById("txtResultado").value = "método GET não suportado";
}
}
}
</script>
aqui vai o código do meu Servlet
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.omg.PortableServer.REQUEST_PROCESSING_POLICY_ID;
public class AjaxResponseServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletResponse res, HttpServletRequest req) throws ServletException, IOException{
String param = req.getParameter("n1");
if (param != null){
int n1 = Integer.parseInt(param);
res.setContentType("text/xml");
res.setHeader("Cache-Control","no-cache");
param = String.valueOf(n1+5);
res.getWriter().write("param");
}
else{
res.setContentType("text/xml");
res.setHeader("Cache-Control","no-cache");
res.getWriter().write("?");
}
}
}
e aqui vai o meu Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>AjaxResponseServlet</servlet-name>
<servlet-class>AjaxResponseServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AjaxResponseServlet</servlet-name>
<url-pattern>/response</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
sempre aparece o Erro 405 , ou seja MEtodo GET não suportado...
se eu escrever o browser o caminho do servled ... neste caso, "response"
me é retornado o erro 405 , seguido da seguinte mensagem:
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/5.5.17
aguém sabe me dizer onde estou errando ??
OBRIGADO XD