@RequestMapping(value="/logout",method=RequestMethod.GET)
public void logout(HttpServletRequest request,HttpServletResponse response)
{
//清除session
Enumeration<String> em = request.getSession().getAttributeNames();
while(em.hasMoreElements()){
request.getSession().removeAttribute(em.nextElement().toString());
}
request.getSession().invalidate();
//获取项目真实路径
String path = request.getContextPath();
//拼接跳转页面路径
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
//刷新页面
String str = "<script>top.location='"+basePath+"'</script>";
System.out.println(str);
responseTxt(response,str);
}
//返回前台页面ajax
protected void responseTxt(HttpServletResponse response,String str){
try {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.write(str);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}