feat: add interceptor
This commit is contained in:
parent
3ac281a2d7
commit
73d145c45b
@ -0,0 +1,24 @@
|
|||||||
|
package cn.edu.cqwu.repair.interceptor;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xtaod
|
||||||
|
*/
|
||||||
|
public class AdminInterceptor implements HandlerInterceptor {
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
if (session != null && session.getAttribute("adminUser") != null) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
request.setAttribute("adminLoginMess", "*请先登录!");
|
||||||
|
request.getRequestDispatcher("/manage.jsp").forward(request, response);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cn.edu.cqwu.repair.interceptor;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xtaod
|
||||||
|
*/
|
||||||
|
public class StuInterceptor implements HandlerInterceptor {
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
if (session != null && session.getAttribute("stu") != null) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
request.setAttribute("stuLoginMess", "*请先登录!");
|
||||||
|
request.getRequestDispatcher("/index.jsp").forward(request, response);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cn.edu.cqwu.repair.interceptor;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xtaod
|
||||||
|
*/
|
||||||
|
public class WorkerInterceptor implements HandlerInterceptor {
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
HttpSession session = request.getSession();
|
||||||
|
if (session != null && session.getAttribute("workerUser") != null) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
request.setAttribute("workerLoginMess", "*请先登录!");
|
||||||
|
request.getRequestDispatcher("/worker_login.jsp").forward(request, response);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -33,4 +33,19 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<mvc:default-servlet-handler />
|
<mvc:default-servlet-handler />
|
||||||
|
|
||||||
|
<mvc:interceptors>
|
||||||
|
<mvc:interceptor>
|
||||||
|
<mvc:mapping path="/stu/**"/>
|
||||||
|
<bean class="cn.edu.cqwu.repair.interceptor.StuInterceptor" />
|
||||||
|
</mvc:interceptor>
|
||||||
|
<mvc:interceptor>
|
||||||
|
<mvc:mapping path="/worker/**"/>
|
||||||
|
<bean class="cn.edu.cqwu.repair.interceptor.WorkerInterceptor" />
|
||||||
|
</mvc:interceptor>
|
||||||
|
<mvc:interceptor>
|
||||||
|
<mvc:mapping path="/admin/**"/>
|
||||||
|
<bean class="cn.edu.cqwu.repair.interceptor.AdminInterceptor" />
|
||||||
|
</mvc:interceptor>
|
||||||
|
</mvc:interceptors>
|
||||||
</beans>
|
</beans>
|
||||||
|
Loading…
Reference in New Issue
Block a user