Created
January 24, 2013 13:15
-
-
Save Niranjan10/4621442 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.Enumeration; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import javax.servlet.http.HttpSession; | |
/** | |
* | |
* @author Nero | |
*/ | |
public class LogoutServlet extends HttpServlet { | |
protected void processRequest(HttpServletRequest request, HttpServletResponse response) | |
throws ServletException, IOException { | |
response.setContentType("text/html;charset=UTF-8"); | |
PrintWriter out = response.getWriter(); | |
try { | |
HttpSession session=request.getSession(true); | |
Enumeration attributeNames=session.getAttributeNames(); //get all attributeNames associated with session | |
while(attributeNames.hasMoreElements()) //destroy session | |
{ | |
String name=(String)attributeNames.nextElement(); | |
String value=session.getAttribute(name).toString(); | |
session.removeAttribute(name); | |
System.out.println(name+"="+value+"cleared"); | |
} | |
// } | |
out.println("<html>"); | |
out.println("<head>"); | |
out.println("<title>Servlet LogoutTestServlet</title>"); | |
out.println("</head>"); | |
out.println("<body>"); | |
out.println("<center><h1>Logged Out Successfully..</h1>"); | |
out.println("<h2><a href=\"login.jsp\">Go to Login Page</a></h2></center>"); | |
out.println("</body>"); | |
out.println("</html>"); | |
} finally { | |
out.close(); | |
} | |
} | |
@Override | |
protected void doGet(HttpServletRequest request, HttpServletResponse response) | |
throws ServletException, IOException { | |
processRequest(request, response); | |
} | |
@Override | |
protected void doPost(HttpServletRequest request, HttpServletResponse response) | |
throws ServletException, IOException { | |
processRequest(request, response); | |
} | |
@Override | |
public String getServletInfo() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment