zoukankan      html  css  js  c++  java
  • 个人博客

    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;
    }
    }

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

  • 相关阅读:
    Linux启动mysql命令
    Linux启动Apache服务器命令
    使用SSH命令从一台Linux远程登陆到另一台Linux
    Linux关机命令
    从Windows复制文件到Linux
    无法访问SVN历史记录的问题
    linux静态IP最简配置
    学习之Redis(二)
    学习之Redis(一)
    MySQL数据库笔记总结
  • 原文地址:https://www.cnblogs.com/yitiaokuailedexiaojingyu/p/14868619.html
Copyright © 2011-2022 走看看