Alguém pode me ajudar, quando tento acessar as paginas LOGIN e CADASTRAR EMPRESA na index.jsp, aparece erro 405 abaixo, talves por esses dois links estarem como doPost()
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.
Apache Tomcat/7.0.47
CODIGO inde.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="pt-br">
<body>
<head>
<meta charset="UTF-8">
</head>
Bem vindo ao sistema de cadastro de empresas</br></br></br></br>
<a href="login" >Login | </a>
<a href="nova-empresa" >Cadastrar empresa | </a>
<a href="busca" >Buscar empresas</a>
</body>
</html>
CODIGO login.java
package br.com.alura.gerenciador.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import br.com.alura.gerenciador.Usuario;
import br.com.alura.gerenciador.dao.UsuarioDAO;
@WebServlet(urlPatterns = "/login")
public class Login extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String email = req.getParameter("email");
String senha = req.getParameter("senha");
String mensagemDeErro = "Usuario e senha invalidos!";
if (email == null && senha == null) {
req.setAttribute("mensagemDeErro", mensagemDeErro);
} else {
validarDados(req, resp, email, senha);
}
}
private void validarDados(HttpServletRequest req, HttpServletResponse resp, String email, String senha)
throws ServletException, IOException {
Usuario usuario = new UsuarioDAO().buscaPorEmailESenha(email, senha);
HttpSession session = req.getSession();
if (usuario != null) {
session.setAttribute("usuarioLogado", usuario);
req.getRequestDispatcher("WEB-INF/paginas/login.jsp").forward(req, resp);
}
}
}
CODIGO login.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="pt-br">
<body>
<head>
<meta charset="UTF-8">
</head>
<c:if test="${ usuarioLogado != null }">
Você está logado como ${usuarioLogado.email}
</c:if>
<form action="login" method="post">
<label for="email">E-MAIL : </label> <input id="email" type="text"
name="email" required="required" maxlength="50"> <label
for="senha">NOME : </label> <input id="senha" type="password"
name="senha" required="required" maxlength="50"> <input
type="submit" value="Enviar">
</form>
<form action="logout">
<input type="submit" value="logout">
</form>
</body>
</html>