01: package forum;
02:
03: import java.io.*;
04: import javax.servlet.*;
05: import javax.servlet.http.*;
06:
07: public class Logout extends HttpServlet {
08:
09: public void doPost(HttpServletRequest request,
10: HttpServletResponse response) throws ServletException,
11: IOException {
12:
13: PrintWriter out = response.getWriter();
14: try {
15: //Cookie[] cookies = request.getCookies();
16: HttpSession session = request.getSession(true);
17:
18: session.removeAttribute("username");
19: session.removeAttribute("password");
20: session.removeAttribute("type");
21: /*
22: if (cookies != null){
23: Cookie cookie;
24: for(int i=0;i<cookies.length;i++){
25: cookie = cookies[i];
26: if(cookie.getName().equals("username")){
27: cookie.setMaxAge(0);
28: response.addCookie(cookie);
29: session.removeAttribute("username");
30: }else if(cookie.getName().equals("password")){
31: cookie.setMaxAge(0);
32: response.addCookie(cookie);
33: session.removeAttribute("password");
34: }else if(cookie.getName().equals("type")){
35: cookie.setMaxAge(0);
36: response.addCookie(cookie);
37: session.removeAttribute("type");
38: }
39:
40: }
41: }*/
42:
43: response
44: .sendRedirect(Variable.getForumPath() + "index.jsp");
45:
46: } catch (Exception e) {
47: out.println(e);
48: }
49: }
50:
51: public void doGet(HttpServletRequest request,
52: HttpServletResponse response) throws ServletException,
53: IOException {
54: doPost(request, response);
55: }
56:
57: }
|