Controle de Sessão

5 respostas
A

Oi pessoal,

Estou com um problema na minha aplicação. Trata-se de expirar a sessão intermitentemente independente de passos ou tempo/frequencia de uso após o login.

Ela possui uma classe que recebe e direciona as requisições (Controller). Um dos passos dela é testar se a sessão do usuário está ativa.

Para isso, faz o seguinte:

...
	if (request.getSession().isNew()) {
		request.setAttribute("texto", "Sessão Inválida");
		dispacher = "SessaoExpirada.jsp";
		response.sendRedirect(dispacher);
	} else 
	...

Alguém tem alguma dica ? Estou usando:

Internet Explorer 6 (não consegui simular no Firefox 3)
WAS OC4J rodando em AIX

Obrigado

Preciso muito de ajuda. Eu não consigo depurar o ambiente de produção e o problema só ocorre lá.

5 Respostas

G

Você poderia postar o código do classe completa? Só com esse trecho fica difícil dizer alguma coisa!

A

Versões:

oc4j 1.0.2.2.1
 java 1.3.1
 aix 5.3

Classe:

package com.multibras.pmp.controller;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**
*

  • Processa a requisição chamando as classes responsáveis por cada uma delas
  • Auxiliares :
  • @author Agnelo de Jesus
  • @since JDK 1.3
  • @see

*/

public class PmpController extends HttpServlet {

/**
 * 
 */
private static final long serialVersionUID = 1803368194068389240L;
/**
 * 
 * Este método foi criado para tratar as requisições de formularios.
 * Ele atua como controlador da aplicação, redirecionando as chamadas
 * aos servlets respectivos e retornado a pagina de resposta correspondente.
 * 
 * Data : 19/02/2004
 * Responsável: Agnelo de Jesus
 * @param: request, response - 
 * @return: int
 * @exception :
 */
public void executar(
	HttpServletRequest request,
	HttpServletResponse response)
	throws ServletException, IOException {
	String command = request.getParameter("command");
	if (command == null) {
		command = (String) request.getSession().getAttribute("comm");
	}

	String dispacher = "Error.jsp";
	if (request.getSession().isNew()) {
		request.setAttribute("texto", "Sessão Inválida");
		dispacher = "SessaoExpirada.jsp";
		response.sendRedirect(dispacher);
	} else {
		if (command == null) {
			dispacher = "Mensagem.jsp";
			request.setAttribute(
				"texto",
				"Essa requisição não podes ser Executada");
		} else {
			PMPCommand pcmd = (PMPCommand) map.get(command);
			dispacher = pcmd.executar(request, response);
		}
		RequestDispatcher rd = request.getRequestDispatcher(dispacher);
		rd.forward(request, response);
	}
}

HashMap map;
/**
 * 
 * Carrega os pares nome, Classe para chamada de cada requisição.
 * 
 * Data : 19/02/2004
 * Responsável: Agnelo de Jesus
 * @param: 
 * @return:
 * @exception :
 */ /**
	 * @see javax.servlet.GenericServlet#init()
	 */
public void init() throws ServletException {
	map = new HashMap();
	map.put("login", new PMPLogin());
	map.put("trocarsenha", new PMPTrocarSenha());
	map.put("pmpcreate", new PMPGeraPMP());
	map.put("gravaResultado", new PMPGravaResultado());
	map.put("gravaComportamento", new PMPGravaComportamento());
	map.put("gravaMyPlan", new PMPGravaMyPlan());
	map.put("selsubordinados", new PMPGeraInfoSubordinado());
	map.put("esquecisenha", new PMPEsqueciSenha());
	map.put("loginResetSenha", new PMPLoginResetSenha());
	map.put("ResetSenha", new PMPResetSenha());
	map.put("mostrapmpsub", new PMPGeraPMPSub());
	map.put("CargaNaoIniciados", new PMPNaoIniciados());
	map.put("alterastatus", new PMPAlteraStatus());
	map.put("alterastatusadmin", new PMPAlteraStatusAdmin());
	map.put("anteriores", new PMPGeraInfoAnteriores());
	map.put("cadcatmeta", new PMPCadastroCategoriaMeta());
	map.put("cadcompetencia", new PMPCadastroCompetencia());
	map.put("cadobjetivo", new PMPCadastroObjDesenvolvimento());
	map.put("cadmetacarreira", new PMPCadastroMetaCarreira());
	map.put("excecao", new PMPCadastroExcecao());
	map.put("cadadmin", new PMPCadastroAdministradores());
	map.put("cadparam", new PMPCadastroParametros());
	map.put("infoAdmin", new PMPGeraInfoAdmin());
	map.put("upload", new PMPUploadNotaCalibracao());
	map.put("conceito", new PMPConceito());
	map.put("alteracaoPmp", new PMPAlterarPmps());
	map.put("adminListaPMPs", new PMPAdminListaPMPs());		
	map.put("adminGerencPMPs", new PMPAdminGerencPMPs());				
	map.put("cadUsuariosList", new PMPCadastroUsuariosList());				
	map.put("cadUsuariosForm", new PMPCadastroUsuariosForm());
	map.put("cadvalorcorrespondente", new PMPCadastroValorCorrespondente());				
	map.put("cadnotaadicional", new PMPCadastroNotaAdicional());
	map.put("cadtexto", new PMPCadastroTexto());
	map.put("cacheMonitor", new PMPCacheMonitor());
	map.put("adminEmailText", new PMPAdmEmailText());
}

/**
*

  • Get

  • Data : 19/02/2004

  • Responsável: Agnelo de Jesus

  • @param: request, response -

  • @return:

  • @exception :
    */

    protected void doGet(
    
    HttpServletRequest request,
    
    HttpServletResponse response)
    
    throws ServletException, IOException {
    
    executar(request, response);
    
    }
    
    /**
    
  • Post

    • Data : 19/02/2004
    • Responsável: Agnelo de Jesus
    • @param: request, response -
    • @return:
    • @exception :
      /
      /
      *
    • @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest, HttpServletResponse)
      */
      protected void doPost(
      HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException {
      executar(request, response);
      }

}

G

Dica: use as tags code nos seus comentarios.

http://www.theserverside.com/discussions/thread.tss?thread_id=21643

public HttpSession getSession(boolean create)Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.

If create is false and the request has no valid HttpSession, this method returns null.

Portanto ao inves de

... if (request.getSession().isNew()) { ...

tente usar

... if (request.getSession(false) != null) { ...

A

Então, mas antes estava
if (request.getSession().isNew()) {

Com o problema, passamos a usar
if(request.getSession(false) == null) {

O erro só ocorre em algumas máquinas. Será que pode ser Internet Explorer ?

G

Mesmo depois da mudança o erro continua ocorrendo?

Criado 7 de janeiro de 2009
Ultima resposta 12 de jan. de 2009
Respostas 5
Participantes 2