Saturday, 17 August 2013

Error 404 that i guess is due to some unknown issue with the web.xml i can't see

Error 404 that i guess is due to some unknown issue with the web.xml i
can't see

I am developing a Web application based on Tomcat 7, and bumped in a
situation where I have no clue what and why is happening. After type my
login credencials in JSP page below:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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>Login</title>
</head>
<body>
<div id="form">
<form method=POST name=login_form action=Login>
Usuário: <input type=text name=username> <br/>
Senha: <input type=password name=password> <br/>
<input type="submit" value="Entrar">
<span class="error">${error}</span>
</form>
</div>
</body>
</html>
I receive the following message, regardless if I entered the right or
wrong credencials:
HTTP Status 404 - /WebApp/Login
type Status report
message /WebApp/Login
description The requested resource is not available.
Apache Tomcat/7.0.42
The implementation for the method doPost of the servlet class is the
following:
String username = request.getParameter("username");
String password = request.getParameter("password");
Date data_login = new Date(System.currentTimeMillis());
java.sql.Timestamp nova_data = new java.sql.Timestamp(0, 0, 0, 0, 0,
0, 0);
nova_data.setDate(data_login.getDay());
nova_data.setMonth(data_login.getMonth());
nova_data.setYear(data_login.getYear());
nova_data.setHours(data_login.getHours());
nova_data.setMinutes(data_login.getMinutes());
nova_data.setSeconds(nova_data.getSeconds());
DataHelper dhelper = new DataHelper();
try {
System.out.println("Registrando login...");
user temp = dhelper.doProcessaLogin(username, password);
if(temp!=null) {
String fname = temp.getFirstName();
String lname = temp.getLastName();
int id = temp.getId();
System.out.println("Dados corretos");
request.getSession().setAttribute("user", fname+" "+lname);
dhelper.doRegistraSessao(fname, lname, nova_data, id);
Cookie ck = new Cookie("User",fname+" "+lname);
ck.setMaxAge(7);
response.addCookie(ck);
request.getRequestDispatcher("/WEB-INF/menu.jsp").forward(request,response);
}
else {
System.out.println("Dados incorretos");
request.getSession().setAttribute("erro", "Não foi possivel
efetuar o login");
System.out.println("Direcionando de volta para a pagina de
login");
request.getRequestDispatcher("/login").forward(request,
response);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I have an implementation for a method doGet too:
request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request,
response);
my web.xml is the following:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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_3_0.xsd" version="3.0">
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>com.webapp.servlet.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
I really don't know the reason the system is looking for /WebApp/Login
instead of /WebApp/login, which is what was declared in the web.xml.
Someone can see any problem with code above?

No comments:

Post a Comment