• 个人博客


    2021年5月7日:

    昨天完善和完整了表格的代码和大部分功能,比如点击详情跳转社团详情页面和点击申请能发送申请表单,今天准备完善之前未完善的部分,例如拦截器的设置和上传头像功能的实现,拦截器我是在配置文件中设置了一个

    <mvc:interceptors>
    <mvc:interceptor>
    <mvc:mapping path="/**" />
    <mvc:exclude-mapping path="/login" />
    <mvc:exclude-mapping path="/logout.html" />
    <mvc:exclude-mapping path="/register" />
    <mvc:exclude-mapping path="/active" />
    <mvc:exclude-mapping path="/statics/**" />
    <bean class="com.atguigu.crud.lanjieqi.LoginInterceptor"></bean>
    </mvc:interceptor>
    <mvc:interceptor>
    <mvc:mapping path="/**" />
    <mvc:exclude-mapping path="/login" />
    <mvc:exclude-mapping path="/user/edit2" />
    <mvc:exclude-mapping path="/logout.html" />
    <mvc:exclude-mapping path="/user/edit" />
    <mvc:exclude-mapping path="/register" />
    <mvc:exclude-mapping path="/active" />
    <mvc:exclude-mapping path="/statics/**" />
    <bean class="com.atguigu.crud.lanjieqi.CompleteInfoInterceptor"></bean>
    </mvc:interceptor>
    </mvc:interceptors>

    然后配置拦截所有的请求除了一些登录和注册之类的请求,之前不知道怎么回事死活弄不出来,后来也不知道怎么弄得就突然好了,可能是我设置拦截器的时候把一些请求给拦截了,这是拦截器的后端代码:

    package com.atguigu.crud.lanjieqi;

    import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

    import com.atguigu.crud.bean.User;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class CompleteInfoInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws Exception {
    User user = (User) request.getSession().getAttribute("user");
    // 如果有用户信息,并且昵称为null,说明没有完善个人资料
    if (user != null && user.getNick_name() == null) {
    response.sendRedirect(request.getContextPath() + "/user/edit?action=change");
    return false;// 拦截
    }
    return true;
    }
    }

    package com.atguigu.crud.lanjieqi;

    import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class LoginInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws Exception {
    Object user = request.getSession().getAttribute("user");
    if (user == null) {
    response.sendRedirect(request.getContextPath() + "/login.jsp");
    return false;
    }
    return true;
    }
    }

    拦截器算是已经完善了,现在还未完善的功能就是修改头像。

  • 相关阅读:
    ZOJ 2158 Truck History
    Knight Moves (zoj 1091 poj2243)BFS
    poj 1270 Following Orders
    poj 2935 Basic Wall Maze (BFS)
    Holedox Moving (zoj 1361 poj 1324)bfs
    ZOJ 1083 Frame Stacking
    zoj 2193 Window Pains
    hdu1412{A} + {B}
    hdu2031进制转换
    openjudge最长单词
  • 原文地址:https://www.cnblogs.com/yitiaokuailedexiaojingyu/p/14868619.html
Copyright © 2020-2023  润新知