Saudações.
Estou executando um servlet no Tomcat.
O servlet chamado Login tem o código:
//package classes;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import classes.*;
public class Login extends HttpServlet {
// Tempo de sessão: 10 minutos
final private static int tempoDeSessao = 10 * 60;
protected void doGet(
final HttpServletRequest req,
final HttpServletResponse res)
throws ServletException, IOException{
res.setContentType("text/html");
res.getWriter().println("<html><header><meta HTTP-EQUIV="Pragma" " +
"CONTENT="no-cache"></header>" +
"<title> Ead ChAt - Ensino á Distância Unerj </title><body>");
res.getWriter().println("Login para o chat: " +
"<form action="" +
this.getClass().getName() +
"" method=post><input name=login><input type=submit" +
" value=Login></form></html>");
}
/* O método POST checa a viabilidade de criar um usuário
* e o cria */
protected void doPost(final HttpServletRequest req,
final HttpServletResponse res)
throws ServletException, IOException{
// Seta o tipo de conteúdo
res.setContentType("text/html");
// Se já existe uma sessão, invalida ela
if (req.getSession() != null
&& req.getSession().getAttribute("user") != null) {
req.getSession().invalidate();
}
try{
// Cria um usuário
Usuario usuario = new UsuarioChat(req.getParameter("login"));
req.getSession().setAttribute("user", usuario);
// Tempo Limite
req.getSession().setMaxInactiveInterval(tempoDeSessao);
}catch(IllegalArgumentException iaex){
// se já existe um usuário, mostra pagina de login novamente
res.getWriter().println("<html><header><meta HTTP-EQUIV="Pragma" CONTENT="no-cache"></header><body>");
res.getWriter().println(
""
+ "
Ja existe um usuario com esse login:<br>"
+ "
<form action="
+ this.getClass().getName()
+ " method=post>"
+ "
<input name=login>"
+ "
<input type=submit value=Login>"
+ "
</form>"
+ "
</html>");
return;
}
// Mostra os dois frames
res.getWriter().print(
"<html>
"
+ " <frameset rows=*,100>
"
+ " <frame name="text" src=""
+ this.getClass().getPackage().getName()
+ ".Sala">
"
+ " <frame name="form" src=""
+ this.getClass().getPackage().getName()
+ ".Form">
"
+ " </frameset>
"
+ "</html>");
return;
}
}
Ele é executado normalmente, mas quando digito o login na caixa de texto e mando e clico em Login aparece:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
Login.doPost(Login.java:68)
javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
Apache Tomcat/5.0.19
Alguém sabe como corrigir?