HttpSession s = request.getSession();
if (s.getAttribute("logged")==null){
s.setAttribute("from",request.getRequestURI());
response.sendRedirect("/login");
}
else {
s.setAttribute("from",request.getRequestURI());
%>Logout<%
//UserService userSer = (UserService)s.getAttribute("userSer");
}
Login.java
public class Login extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
UserService userSer=UserServiceFactory.getUserService();
User u=userSer.getCurrentUser();
HttpSession s=request.getSession();
String from=(String)s.getAttribute("from");
s.setAttribute("logged","yes");
s.setAttribute("userSer", userSer);
response.sendRedirect(userSer.createLoginURL(from));
}
}
Logout.java
public class Logout extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession s = request.getSession();
String from=(String)s.getAttribute("from");
UserService us=(UserService)s.getAttribute("userSer");
s.invalidate();
response.sendRedirect(us.createLogoutURL("/index.html"));
}
}
No comments:
Post a Comment