Pessoal,
Tenho algumas variaveis de sessão instanciadas em uma servlet.
Uma classe precisa ler essas variaveis de sessão.
Fiz assim: (não deu certo)
package model;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class FiltroProjetos {
private ConexaoMysql conexaoMysql;
public String FiltroProjetos2(String status){
conexaoMysql = new ConexaoMysql();
Statement state = null;
ResultSet rs = null;
String nome = "";
System.out.println(session.getAttribute("perfil")); // tento exibir a variavel de sessao para saber se ela foi pega corretamente
try {
state = conexaoMysql.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = state.executeQuery("Select nome from projeto where statusProjeto = '" + status + "'");
while (rs.next()) {
nome += rs.getString("nome") + "#";
//System.out.println("Nome:" + nome);
}
} catch(Exception erro) {
System.out.println("Erro ocorrido na classe FiltroProjetos: n" + erro);
} finally {
if(state != null){ //fechar os statments
try {
state.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return nome;
}
}
Ai tentei fazer assim:
package model;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class FiltroProjetos {
private ConexaoMysql conexaoMysql;
public void Filtro (HttpServletRequest request){
HttpSession session = request.getSession();
//String matricula = (String)session.getAttribute("login");
//session.getAttribute("perfil");
System.out.println("Esse é o meu perfil: " + session.getAttribute("perfil"));
//String matricula = (String)session.getAttribute("login");
}
public String FiltroProjetos2(String status){
conexaoMysql = new ConexaoMysql();
Statement state = null;
ResultSet rs = null;
String nome = "";
Filtro(); // Aki tem que passar um valor mas não sei ql valor eu tenho q passar para dar certo.
try {
state = conexaoMysql.getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = state.executeQuery("Select nome from projeto where statusProjeto = '" + status + "'");
while (rs.next()) {
nome += rs.getString("nome") + "#";
//System.out.println("Nome:" + nome);
}
} catch(Exception erro) {
System.out.println("Erro ocorrido na classe FiltroProjetos: n" + erro);
} finally {
if(state != null){ //fechar os statments
try {
state.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return nome;
}
}
Qual valor eu tenho que passar para isso dê certo? Tem outra solução?
???