一、项目简述
功能: 区分为管理员用户和普通用户,普通用户:用户注册登 录,首页水果展示,商品分类展示,购物车添加,下单, 订单查询,个人信息修改,管理员用户:包括水果基本信 息维护增删改查,分类管理,订单管理,用户管理等等功 能。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP + Struts + Spring + Hibernate + html + css + JavaScript + JQuery等等。
用户登录拦截器代码:
@WebFilter(filterName="CheckLoginFilter",value="/back/*",initParams=@WebInitParam(name="errorPage",value="index.html"))
public class CheckLoginFilter implements Filter{
private String path = "index.html";
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) arg0;
HttpServletResponse response = (HttpServletResponse) arg1;
HttpSession session = request.getSession();
if (session.getAttribute("currentLoginUser") == null) { // 说明用户没有登录
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() + request.getContextPath() +"/";
out.print("<script>alert('请先登录...');location.href='" + basePath + path + "';</script>");
out.flush();
out.close();
} else { // 如果已经登录,则交给下一个过滤器过滤
chain.doFilter(request, response);
}
}
@Override
public void init(FilterConfig arg0) throws ServletException {
String tmp = arg0.getInitParameter("errorPage");
if (tmp != null) {
path = tmp;
}
}
}