首页 > 其他分享 >springMVC的controller中获取request,response对象的两个方法

springMVC的controller中获取request,response对象的两个方法

时间:2023-06-01 23:07:17浏览次数:48  
标签:return springMVC request HttpServletResponse controller user attributes response


@GetMapping("outLogin") 
    public String outLogin(){
        
        ServletRequestAttributes attributes=(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();

        HttpServletRequest request = attributes.getRequest();
        
        HttpServletResponse response = attributes.getResponse();
        
        CookieUtils.deleteCookie(request , response ,"token");
        
        return "已退出系统";
    }

 

@GetMapping("/login")
    public String LoginUser(User user, HttpServletRequest request , HttpServletResponse response){
        if(user.getUsername().equals("admin") && user.getPassword().equals("123")){
            CookieUtils.setCookie(request , response , "token" ,"456456456",60*60,"utf-8");
            return "登录成功";
        }
        return "登录失败";
    }

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:return,springMVC,request,HttpServletResponse,controller,user,attributes,response
From: https://blog.51cto.com/u_14671216/6398489

相关文章

  • requestAnimationFrame
    requestAnimationFrame是一个用于优化浏览器动画效果的API。它可以让浏览器在下一次重绘前执行指定的回调函数,从而可以更加流畅地执行动画效果,避免了使用setTimeout或setInterval可能引起的性能问题。requestAnimationFrame的用法非常简单,只需要在回调函数中编写动画效果......
  • 合理设置K8S中的Requests和Limits
    所有容器都应该设置Requestsrequests的值并不是指给容器实际分配的资源大小,它仅仅是给调度器看的,调度器会"观察"每个节点可以用于分配的资源有多少,也知道每个节点已经被分配了多少资源。被分配资源的大小就是节点上所有Pod中定义的容器requests之和,它可以计算出节点剩余多......
  • 根据Servie接口 生成 Controller 代码-因业务需要简单应付勿喷
    附上垃圾代码(勿喷,只不过为了应付工作需求,百十来个service都要创建对应的controller的需求,复制实在吃不消,说明一下就是简单的字符串替换操作)ApplicationControllerimportjava.io.BufferedReader;importjava.io.File;importjava.io.FileReader;importjava.io.IOExcepti......
  • 400 (Bad Request)
    出现这种情况极有可能是form表单的字段类型与bean中的类型不一致,无法映射导致的 比如:<inputtype="radio"name="isAvailable"value="是"checked="checked">启用javabean中却定义成 privateintisAvailable; 这时,value值"是"无法映射到数值类型的isAvail......
  • HTTP/1.1 Request/Response
    https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.htmlhttps://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html RequestsHeader|HttpHeaderHeader解释示例Accept指定客户端能够接收的内容类型Accept:text/plain,text/htmlAccept-Charset浏览器可以接......
  • 使用SpringMVC搭建第一个项目
    概述使用SpringMVC搭建第一个项目,入门教程,分享给大家。详细一、概述1、什么是SpringMVC?SpringMVC属于SpringFrameWork的后续产品,已经融合在SpringWebFlow里面。Spring框架提供了构建Web应用程序的全功能MVC模块。使用Spring可插入的MVC架构,从而在使用Sp......
  • 前端 React + vite + Typescript 后端 java + springmvc + jwt 跨域 解决方案
    首先后端配置跨域:web.xml文件: <!--配置跨域--><filter><filter-name>header</filter-name><filter-class>org.zhiyi.config.Cross</filter-class></filter><filter-mapping><......
  • 根据视频帧率,使用requestAnimationFrame播放动画
    当时使用webRTC进行视频通话时,通常会设置视频流的帧率,行业内一般默认帧数为15或者30,一般每秒只需要渲染15或30次当要需要对本地视频或者远端视频流进行特殊处理时,通常会使用requestAnimationFrame方法进行再次渲染requestAnimationFrame,这个方法是用来在页面重绘之前,通知浏览器......
  • 果然python是直接可以使用requests去请求https站点的,意味着一般的扫描工具可以直接扫
    #coding:utf-8importrequests#请求地址#url="https://www.qlchat.com"url="https://www.baidu.com"headers={'user-agent':'Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chro......
  • unable to find valid certification path to requested target
    发生这种情况时,很有可能与证书无关,而是某个第三方类库获取不到了我的解决方案,找到原版本的AAR文件放到工程的LIBs目录中,引用到工程中 unabletofindvalidcertificationpathtorequestedtarget最新解决方案(更新于2023-04-08)置顶da_caoyuan已于 2023-04-0811......