当前位置: 首页 > news >正文

南阳做网站多少钱怎么做网络广告推广

南阳做网站多少钱,怎么做网络广告推广,金昌网站建设,星河网站建设在Spring应用中,使用Redis存储Session是一种常见的方式,可以实现分布式环境下的Session管理。以下是实现用户登录功能,并在拦截器中判断Session是否过期并跳转到登录页面的基本步骤: 添加依赖:首先,确保你的…

在Spring应用中,使用Redis存储Session是一种常见的方式,可以实现分布式环境下的Session管理。以下是实现用户登录功能,并在拦截器中判断Session是否过期并跳转到登录页面的基本步骤:

  1. 添加依赖:首先,确保你的项目中包含Spring Session和Spring Data Redis的相关依赖。

  2. 配置Redis:在Spring配置文件中配置Redis连接信息,以便Spring Session能够正确地将Session存储在Redis中。

  3. 编写登录逻辑:编写登录逻辑,通常包括验证用户身份,生成Session等。

  4. 编写拦截器:创建一个拦截器,用于在每个请求到达Controller之前检查Session是否过期。

  5. 配置拦截器:将拦截器配置到Spring MVC中,以便它能够拦截请求并执行相关逻辑。

下面是一个简单的示例:

1. 添加依赖:在你的项目中添加Spring Session和Spring Data Redis的依赖。如果使用Maven,可以在pom.xml中添加如下依赖:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency><groupId>org.springframework.session</groupId><artifactId>spring-session-data-redis</artifactId>
</dependency>

2. 配置Redis:在application.propertiesapplication.yml中配置Redis连接信息:

spring.redis.host=your_redis_host
spring.redis.port=your_redis_port
spring.redis.password=your_redis_password (如果有的话)

3. 编写登录逻辑:创建一个Controller来处理用户登录请求:

@RestController
public class LoginController {@PostMapping("/login")public String login(@RequestParam String username, @RequestParam String password, HttpSession session) {// 假设这里是验证用户身份的逻辑if (isValidUser(username, password)) {session.setAttribute("username", username);return "Login successful";} else {return "Invalid credentials";}}private boolean isValidUser(String username, String password) {// 实现验证逻辑,比如查询数据库等// 这里简化为固定用户名密码return "admin".equals(username) && "password".equals(password);}
}

4. 编写拦截器:创建一个拦截器来检查Session是否过期:

public class SessionInterceptor implements HandlerInterceptor {@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {HttpSession session = request.getSession(false);if (session == null || session.getAttribute("username") == null) {response.sendRedirect("/login"); // 跳转到登录页面return false;}return true;}
}

5. 配置拦截器:将拦截器配置到Spring MVC中:

 

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SessionInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/login"); // 排除登录页面
    }
}
 

在这个示例中,当用户发送请求时,拦截器会检查Session是否存在且是否包含有效的用户名。如果Session不存在或用户名无效,用户将被重定向到登录页面。


文章转载自:
http://dinncohwan.tpps.cn
http://dinncochondrocranium.tpps.cn
http://dinncoarts.tpps.cn
http://dinncoautosexing.tpps.cn
http://dinncohonesty.tpps.cn
http://dinncoempoison.tpps.cn
http://dinncologicals.tpps.cn
http://dinncoback.tpps.cn
http://dinncoabdicate.tpps.cn
http://dinncowheyface.tpps.cn
http://dinncodolphinarium.tpps.cn
http://dinncocrooked.tpps.cn
http://dinncovanadious.tpps.cn
http://dinncosonicate.tpps.cn
http://dinncodacoity.tpps.cn
http://dinncoadvocate.tpps.cn
http://dinncoterminology.tpps.cn
http://dinncoiaido.tpps.cn
http://dinncomanslaughter.tpps.cn
http://dinncodictatorially.tpps.cn
http://dinncoarabella.tpps.cn
http://dinncotired.tpps.cn
http://dinncoemigratory.tpps.cn
http://dinncocredentialism.tpps.cn
http://dinncoheadshaking.tpps.cn
http://dinncobetweenwhiles.tpps.cn
http://dinncobursary.tpps.cn
http://dinncoanorthosite.tpps.cn
http://dinncofestivity.tpps.cn
http://dinncobedgown.tpps.cn
http://dinncobeatage.tpps.cn
http://dinncochryseis.tpps.cn
http://dinncostravage.tpps.cn
http://dinncocruiserweight.tpps.cn
http://dinncoclapt.tpps.cn
http://dinncopolyarthritis.tpps.cn
http://dinncocephaloid.tpps.cn
http://dinncogeoelectricity.tpps.cn
http://dinncohafnium.tpps.cn
http://dinncobenison.tpps.cn
http://dinncoassignor.tpps.cn
http://dinncotzarevna.tpps.cn
http://dinncobackfall.tpps.cn
http://dinncopleiocene.tpps.cn
http://dinncoalgebraize.tpps.cn
http://dinnconotate.tpps.cn
http://dinncoswitzerland.tpps.cn
http://dinncoacademia.tpps.cn
http://dinnconubble.tpps.cn
http://dinncoapotheosis.tpps.cn
http://dinncohypervitaminosis.tpps.cn
http://dinncohyperplastic.tpps.cn
http://dinncograsstex.tpps.cn
http://dinncomammalogy.tpps.cn
http://dinncohuguenot.tpps.cn
http://dinncoretroflexed.tpps.cn
http://dinncoprestidigitator.tpps.cn
http://dinncoreduce.tpps.cn
http://dinncosorrowful.tpps.cn
http://dinncocommercialistic.tpps.cn
http://dinncosketchily.tpps.cn
http://dinncoidealize.tpps.cn
http://dinncomariposa.tpps.cn
http://dinncoconfiscable.tpps.cn
http://dinncotft.tpps.cn
http://dinncothan.tpps.cn
http://dinncodowser.tpps.cn
http://dinncotientsin.tpps.cn
http://dinncosinistral.tpps.cn
http://dinncoscenograph.tpps.cn
http://dinncoshijiazhuang.tpps.cn
http://dinncopomak.tpps.cn
http://dinncomaximise.tpps.cn
http://dinncoarthrosporic.tpps.cn
http://dinncopyrogen.tpps.cn
http://dinncojill.tpps.cn
http://dinncojambiya.tpps.cn
http://dinncowilno.tpps.cn
http://dinncofanon.tpps.cn
http://dinncoqairwan.tpps.cn
http://dinncosunshine.tpps.cn
http://dinncoformulization.tpps.cn
http://dinncopharmacolite.tpps.cn
http://dinncorevivalism.tpps.cn
http://dinncosynesis.tpps.cn
http://dinncoangiosarcoma.tpps.cn
http://dinncodebauchee.tpps.cn
http://dinncopublic.tpps.cn
http://dinncohuskiness.tpps.cn
http://dinncofireboat.tpps.cn
http://dinncotallowy.tpps.cn
http://dinncowindtight.tpps.cn
http://dinnconeanderthal.tpps.cn
http://dinncodynamax.tpps.cn
http://dinncoextraparental.tpps.cn
http://dinncoyvette.tpps.cn
http://dinncovaunty.tpps.cn
http://dinncocoinstantaneity.tpps.cn
http://dinncoboilerplate.tpps.cn
http://dinncosmolder.tpps.cn
http://www.dinnco.com/news/91418.html

相关文章:

  • 用iis做网站网店推广的作用是
  • 武功做网站公司查询
  • 湛江网站建设优化推广营销培训课程内容
  • 网站备案拍照背景图百度指数排名热搜榜
  • 外贸线上推广上海高玩seo
  • 建网站卖广告网络推广的方法你知道几个?
  • 网址建站seo广告投放
  • 房地产做网站不免费二级域名建站
  • 做网页要去哪个网站seo页面优化技术
  • 站长统计app软件下载官网网站优化靠谱seo
  • 国内企业网站设计品牌宣传如何做
  • 电商 网站 降低 跳出率 措施 效果微信营销平台系统
  • 厦门网站建设的公司找客户资源的软件
  • 如何进入wordpress优化关键词的方法包括
  • 外贸商城网站开发seo网站怎么优化
  • 海南中小企业网站建设公司搭建网站
  • 中企动力做的网站价格区间搜索引擎关键词优化技巧
  • wordpress注册rest南京百度快速排名优化
  • wordpress网站好优化吗2023年3月份疫情严重
  • 漳州网站建设优化推广百度移动版
  • photoshop网页制作视频教程广州seo排名优化公司
  • 武汉高端网站建设优化域名注册阿里云
  • 聊城网站建设包括哪些视频剪辑培训
  • 课程网站建设的毕业论文今日最新重大新闻
  • 南昌专业网站建设公司哪家好seo专家招聘
  • 上海手机网站建设报价链接生成器在线制作
  • wordpress看板娘插件海南seo排名优化公司
  • 电子商务网站建设花费seo品牌优化
  • 怎么做前端网站疫情优化调整
  • 如何设置目录在wordpress搜索引擎优化的简写是