Problemas para criar HttpSession

0 respostas
ribclauport

Boa Tade, eu estou tentando criar uma sessão através do seguinte código.

package meupacote;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class for Servlet: ServletSessionPagUm
 *
 */
 public class ServletSessionPagUm extends javax.servlet.http.HttpServlet {
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ServletSessionPagUm() {
		super();
	} 
	
	/* (non-Javadoc)
	 * @see javax.servlet.Servlet#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession sessao = request.getSession(true); 
		sessao.setAttribute("nome", "Edson"); 
		sessao.setMaxInactiveInterval(1); 
		String html = "<html><head>"+
		"<title>Trabalhando com Sessão</title>"+
		"</head>"+
		"<body>" +
		"Sua sessão foi criada com sucesso!<br />"+
		"Sua ID é: <strong>" + sessao.getId( ) + "</strong><br />"+  
		"O tempo máximo de inatividade é: <strong>" +
 		sessao.getMaxInactiveInterval( ) + 
		"</strong> segundo(s)<br />"+ 
		"<a href=\"ServletSessionPagDois\">Clique aqui</a>"+
		" para ver a sessão na página seguinte."+	
		"</body></html>";
		
	    response.setContentType("text/html");
	    PrintWriter writer = response.getWriter( );
	    writer.print(html);  
	    writer.close( );	


	}  	  	  	  
	
	/* (non-Javadoc)
	 * @see javax.servlet.GenericServlet#init()
	 */
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}   
}

porém quando eu chamo a servlet recebo uma janela pedindo para salvar ou localizar o arquivo, quando escolho salvar, não consigo recuperar depois para resgatar a sessão, enfim no livro do Edson Gonçalves o exemplo abre diretamente a página para mandar para outra servlet que resgatará a sessão estou usando o windows xp, alguém poderia me ajudar?

Criado 25 de agosto de 2009
Respostas 0
Participantes 1