Gostaria de saber como posso trabalhar com sessões… estou trabalhando com servlets… gostaria que o usuário que acessar minha página fique com sua sessão aberta ate quando terminar a navegação… sem precisar ficar logando no sistema quando entrar em uma página que precise ser usuário cadastrado…
The getSession method of the HttpServletRequest object returns a user’s session. When you call the method with its create argument as true, the implementation creates a session if necessary.
To properly maintain the session, you must call getSession before any output is written to the response. (If you respond using a Writer, then you must call getSession before accessing the Writer, not just before sending any response data.)
The Duke’s Bookstore example uses session tracking to keep track of the books in the user’s shopping cart. Here is an example of the CatalogServlet getting a session for a user:
publicclassCatalogServletextendsHttpServlet{ publicvoiddoGet(HttpServletRequest request,HttpServletResponseresponse)throwsServletException,IOException{//Gettheuser's session and shopping cartHttpSessionsession=request.getSession(true);...out=response.getWriter();...}}
Dá uma olhada no tutorial da Sun para Servlets…
[]'s
B
baiano_mg
Basta pegar a sessão no servlet com o método getSession da request (como disse o leandrolima).
Usando o parametro true no método vc cria uma nova sessão, se não houver uma instanciada.
Aí é só trabalhar com ela.
Acho q isso resolve seu problema
Leandro_Rangel_Santo
O HttpServletRequest ja tem o metodo HttpSession getSession() que faz o mesmo que o HttpSession getSession(true)
fora isso ,seria bom você ajustar tb o timeout ,para garantir que a sessão sera mantida