springMVC中controller之前执行的方法
2016-07-14 16:32
495 查看
@ModelAttribute()
public void getSessionUser() throws IOException, ServletException {
HttpSession session = getSession();
if (getLoginInfoFromSession()==null) {
session.setMaxInactiveInterval(60*60);
HttpServletRequest request = getRequest();
String userId = request.getParameter("userId");
String roleType = request.getParameter("roleType");
if(userId==null||roleType==null){
request.getRequestDispatcher(request.getContextPath() + "/pages/error/500.html").forward(request, getResponse());
// getResponse().sendRedirect(request.getContextPath() + "/pages/error/500.html");
return;
}
List<AdminUser> adminUserList = adminUserService.getListByProperty("loginId",userId);
LoginInfo loginInfo = new LoginInfo();
AdminUser adminUser = adminUserList.get(0);
if(adminUser.getSupplier()!=null&&AdminUser.ROLE_TYPE_SUPPLIER.equals(roleType)){
loginInfo.setSupplierId(adminUser.getSupplier().getId());
loginInfo.setSupplierName(adminUser.getSupplier().getSupplierName());
}
loginInfo.setRoleType(roleType);
loginInfo.setAdminUser(adminUser);
session.setAttribute(SESSION_LOGIN_INFO, loginInfo);
}
}
public void getSessionUser() throws IOException, ServletException {
HttpSession session = getSession();
if (getLoginInfoFromSession()==null) {
session.setMaxInactiveInterval(60*60);
HttpServletRequest request = getRequest();
String userId = request.getParameter("userId");
String roleType = request.getParameter("roleType");
if(userId==null||roleType==null){
request.getRequestDispatcher(request.getContextPath() + "/pages/error/500.html").forward(request, getResponse());
// getResponse().sendRedirect(request.getContextPath() + "/pages/error/500.html");
return;
}
List<AdminUser> adminUserList = adminUserService.getListByProperty("loginId",userId);
LoginInfo loginInfo = new LoginInfo();
AdminUser adminUser = adminUserList.get(0);
if(adminUser.getSupplier()!=null&&AdminUser.ROLE_TYPE_SUPPLIER.equals(roleType)){
loginInfo.setSupplierId(adminUser.getSupplier().getId());
loginInfo.setSupplierName(adminUser.getSupplier().getSupplierName());
}
loginInfo.setRoleType(roleType);
loginInfo.setAdminUser(adminUser);
session.setAttribute(SESSION_LOGIN_INFO, loginInfo);
}
}
相关文章推荐
- RxJava操作符之创建操作符
- java——动态代理
- eclipse关联github的详细方法
- Java freeMarker2.3.23框架 中文api 地址
- Java Executors(线程池)
- Java实现简单的邮件轰炸机之Java邮件发送器的设计与实现
- Integer类型数据相等问题
- JAVA代码一些关键点的解析
- Java Web学习(14):阶段项目小案例之实现用户登录(不使用数据库)
- Eclipse4.4安装旧版本插件报错 Failed to prepare partial IU
- JAVA开源项目
- spring MVC 框架的搭建(myeclipse +maven)--(下)
- 全面解析java注解
- 解析类型 javax.swing.JComponent的问题处理
- Java字节码进制转换
- java多线程实现(thread和runnable接口两种方式以及其区别)
- Spring AOP的实现机制
- ava千百问_08JDK详解(014)_如何编写JVMTI agent程序
- Java:String和Date、Timestamp之间的转换 博客分类: 我的Java Javadatestringtimestamp 一、String与Date(java.util.Date)
- Java内排序算法一