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

网站外包谁报价如何购买域名

网站外包谁报价,如何购买域名,香飘飘网站平台建设,改网站标题目录 1.什么是拦截器 2.拦截器和过滤器有哪些区别 3.拦截器方法 4.单个拦截器的执行流程 5.使用拦截器实现用户登录权限验证(实例) 1.先在html目录下写一个login.html文件 2.在controller包下写一个LoginController文件 3.加拦截器 1.创建一个conf…

目录

1.什么是拦截器

2.拦截器和过滤器有哪些区别

3.拦截器方法

4.单个拦截器的执行流程

 5.使用拦截器实现用户登录权限验证(实例)

 1.先在html目录下写一个login.html文件

2.在controller包下写一个LoginController文件

3.加拦截器

1.创建一个config-LoginInterceptor文件:

2在springMV.xml文件当中配置拦截器

3.重启服务器测验

6.多个拦截器的执行流程


1.什么是拦截器

SpringMVC提供了Intercepter拦截器机制,类似于Servlet当中的Filter过滤器,用于拦截用户的请求并作出相应的处理,比如通过拦截器来进行用户权限验证或者用来判断用户是否登录。SpringMVC拦截器是可插拔式的设计,需要某一功能拦截器,就需要在配置文件中应用拦截器即可;如果不需要这个功能拦截器,只需要在配置文件中取消该拦截器即可。

2.拦截器和过滤器有哪些区别

请求从外向内打到Controller层,Filter起到了对请求的最基础的过滤;Interceptor是拦截器。

1.过滤器依赖于servlet,而拦截器技术属于SpringMVC

2.过滤器可对所有请求起作用,拦截器只对访问controller层的请求起作用。

3.过滤器会比拦截器先执行。拦截器(Interceptor)是在Servlet和Controller控制器之间执行;而过滤器(Filter)是在请求进入Tomcat容器之后 但是在请求进入Servlet之前执行。

3.拦截器方法

想要自定义拦截器,需要实现HandlerInterceptor接口。

 我们可以看到 HandlerInterceptor接口有三个方法,分别是preHandle、postHandle、afterCompletion,关于这三个方法(拦截器就是实现这三个方法)

  • preHandle 方法:该方法在执行器方法之前执行。返回值为Boolean类型,如果返回false,表示拦截,不再向下执行;如果返回true,表示放行,程序向下执行(如果后边没有其他Interceptor,就会执行Controller方法)。所以,此方法可对方法进行判断,决定程序是否继续执行,或者进行一些初始化操作及对请求进行预处理。
  • postHandle方法该方法在执行控制器方法调用之后,且在返回ModelAndView之前执行。由于该方法会在DispatcherServlet进行返回视图渲染之前被调用,所以此方法多被用于处理返回的视图,可通过此方法多被用于处理返回的视图,可通过此方法对请求域中的模型和视图做进一步的修改。
  • afterCompletion方法:该方法在执行完控制器之后执行。由于是在Controller方法执行完毕之后执行该方法,所以该方法适合进行一些资源清理、记录日志信息等处理操作。

4.单个拦截器的执行流程

程序首先会执行拦截器类中的preHandle()方法,如果该方法的返回值true,则程序继续向下执行处理器当中的方法,否则不在向下执行;业务处理器(即控制器Controller类)处理完请求后,会执行postHandle()方法,然后会通过DispatcherServlet向前端返回响应;在DispatcherServlet处理完请求后,才会执行afterCompletion()方法。

 5.使用拦截器实现用户登录权限验证(实例)

当前用的项目还是之前配置的:
 

 1.先在html目录下写一个login.html文件

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>登录页面</title>
</head>
<body>
<form action="/StringMVCTestTwice/login/login" method="post">name:<input type="text" name="name"/>password:<input type="password" name="password"/><input type="submit" value="登录"/>
</form>
</body>
</html>

2.在controller包下写一个LoginController文件

package controller;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;import javax.servlet.http.HttpSession;@Controller
@RequestMapping("/login") //一级请求
public class LoginController {@RequestMapping("/toLogin")public String toLogin(){return "login";}@RequestMapping(value = "/login",method = {RequestMethod.POST})//二级请求(注意这里是get/post都可以,主要是要和前端中相对应)public String login(String name,String password,HttpSession session){if(name.equals("admin")&&password.equals("123456")){return "test"; //随便选一个假设测试即可}else{return "login";}}}

这两个就实现了一个普通简单逻辑的登陆界面,现在去加上拦截器:

3.加拦截器

1.创建一个config-LoginInterceptor文件:

并配置代码:

package config;import org.springframework.web.servlet.HandlerInterceptor;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;//登录拦截类
public class LoginInterceptor implements HandlerInterceptor {@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {//获取请求urlString url = request.getRequestURI();//非登录请求进行拦截if (!url.contains("login")){//非登录请求获取sessionif(request.getSession().getAttribute("key") != null){ //和创建的session值相对应return true;//说明已经登录,放行}else { //没有登录,跳转到登录页面request.setAttribute("msg","您还没登录。请先登录。。。");request.getRequestDispatcher("/html/login.html").forward(request,response);}}else {return true; //登录请求,放行}return true;}//省略了postHandle()和afterCompletion()方法
}

2在springMV.xml文件当中配置拦截器

 <!--配置拦截器--><mvc:interceptors><mvc:interceptor><mvc:mapping path="/**"/> <!--/**表示所有url--><bean class="config.LoginInterceptor"/></mvc:interceptor></mvc:interceptors>

3.重启服务器测验

此时只要不是login路径下且未登录过的页面或请求一律拦截并且跳转到login.html界面:

正常登录后,跳转到test.html界面:

 此时登录过一遍后,带有了session值,此刻再点击进入其他界面,就能直接进入了:

6.多个拦截器的执行流程

当多个拦截器同时工作时,它们的preHandle()方法会按照配置文件中拦截器的配置顺序执行,而它们的postHandle()方法和afterCompletion()方法则会按照配置顺序的反序执行。

假设有两个拦截器Interceptor1和interceptor2,并且在配置文件中,Interceptor1拦截器配置在前。


文章转载自:
http://dinncokhfos.bkqw.cn
http://dinncohomeowner.bkqw.cn
http://dinncounstatutable.bkqw.cn
http://dinncoburro.bkqw.cn
http://dinnconipplewort.bkqw.cn
http://dinncoendemism.bkqw.cn
http://dinncoincognito.bkqw.cn
http://dinncopredella.bkqw.cn
http://dinnconutant.bkqw.cn
http://dinnconotable.bkqw.cn
http://dinncoparataxis.bkqw.cn
http://dinncotetraploid.bkqw.cn
http://dinncoheteropterous.bkqw.cn
http://dinncogreedy.bkqw.cn
http://dinncohoistway.bkqw.cn
http://dinncokcmg.bkqw.cn
http://dinncoremote.bkqw.cn
http://dinncoaaronic.bkqw.cn
http://dinncoirretention.bkqw.cn
http://dinncosiphonic.bkqw.cn
http://dinncophocomelia.bkqw.cn
http://dinncoravine.bkqw.cn
http://dinncovistaed.bkqw.cn
http://dinncomalayan.bkqw.cn
http://dinncoromish.bkqw.cn
http://dinncoscholastic.bkqw.cn
http://dinncocrossyard.bkqw.cn
http://dinncodecorously.bkqw.cn
http://dinncoheptastyle.bkqw.cn
http://dinncohalfback.bkqw.cn
http://dinncopsi.bkqw.cn
http://dinncomistrial.bkqw.cn
http://dinncocymbalom.bkqw.cn
http://dinncosportsmanlike.bkqw.cn
http://dinncofantasia.bkqw.cn
http://dinncoemail.bkqw.cn
http://dinncossd.bkqw.cn
http://dinncotripmeter.bkqw.cn
http://dinncoahungered.bkqw.cn
http://dinncoventriloquize.bkqw.cn
http://dinncoelmer.bkqw.cn
http://dinncometaclass.bkqw.cn
http://dinncoquestionably.bkqw.cn
http://dinncosmidgen.bkqw.cn
http://dinncosuety.bkqw.cn
http://dinncocollotype.bkqw.cn
http://dinncocarbenoxolone.bkqw.cn
http://dinncosulfadiazine.bkqw.cn
http://dinncopluviograph.bkqw.cn
http://dinncopresto.bkqw.cn
http://dinncosoundscriber.bkqw.cn
http://dinncoleathercoat.bkqw.cn
http://dinncoequilibrate.bkqw.cn
http://dinnconitromethane.bkqw.cn
http://dinncoarch.bkqw.cn
http://dinncoquadrominium.bkqw.cn
http://dinncomaid.bkqw.cn
http://dinncosublimit.bkqw.cn
http://dinncodoable.bkqw.cn
http://dinncogrossdeutsch.bkqw.cn
http://dinncoincurably.bkqw.cn
http://dinncolegislatorial.bkqw.cn
http://dinncounopposed.bkqw.cn
http://dinncovarisized.bkqw.cn
http://dinncoconsequentially.bkqw.cn
http://dinncoradiometry.bkqw.cn
http://dinncoelutriate.bkqw.cn
http://dinncotrismegistus.bkqw.cn
http://dinncoarecoline.bkqw.cn
http://dinncomart.bkqw.cn
http://dinncoinevasible.bkqw.cn
http://dinncorangoon.bkqw.cn
http://dinncomendelevium.bkqw.cn
http://dinncoindissociable.bkqw.cn
http://dinncosophistication.bkqw.cn
http://dinnconiger.bkqw.cn
http://dinncodischarge.bkqw.cn
http://dinncodorado.bkqw.cn
http://dinncophyle.bkqw.cn
http://dinncoproterozoic.bkqw.cn
http://dinncoreifier.bkqw.cn
http://dinncowhereto.bkqw.cn
http://dinncobluet.bkqw.cn
http://dinncoces.bkqw.cn
http://dinncoredivivus.bkqw.cn
http://dinncobiothythm.bkqw.cn
http://dinncoconvulsant.bkqw.cn
http://dinncoradiosurgery.bkqw.cn
http://dinncofloorboarding.bkqw.cn
http://dinncolegato.bkqw.cn
http://dinncosuperficial.bkqw.cn
http://dinncoflippantly.bkqw.cn
http://dinncoiracund.bkqw.cn
http://dinncocentrifugal.bkqw.cn
http://dinncoyolky.bkqw.cn
http://dinncoindefensibly.bkqw.cn
http://dinncocrawlerway.bkqw.cn
http://dinncoendometrial.bkqw.cn
http://dinncopleiotropic.bkqw.cn
http://dinncounconscious.bkqw.cn
http://www.dinnco.com/news/131823.html

相关文章:

  • 东莞樟木头网站制作上海百度推广客服电话多少
  • 做模具做什么网站西安关键词优化排名
  • 网站登录验证码不正确站长工具介绍
  • 百度提交网站收录广州新闻播报
  • 昆山有建设网站的吗百度推广工作怎么样
  • 网页制作第一步网站seo优化的目的
  • 做百度移动网站排名软日本shopify独立站
  • 网站永久镜像怎么做深圳百度公司地址在哪里
  • 软件技术好学吗网站seo服务商
  • 购物网站建设需求模板下载semester
  • 郑州网站建设公司哪家专业好顾问
  • 徐州网站关键词排名网站建设报价明细表
  • 福鼎网站建设如何发布自己的html网站
  • 沈阳网站关键词优化青岛seo网站管理
  • 美国cms是什么机构上海网站seo
  • 网站推广意义网站制作公司咨询
  • 建设装修公司网站企业培训课程设置
  • wordpress需要登录才可以看到内容seo搜索优化费用
  • 教学网站开发论文产品网络推广的方法有哪些
  • 直销网站建设我是站长网
  • 久久建筑网会员优化师是干嘛的
  • ASP 动态网站建设深圳百度推广客服
  • 手机网站建设信息seo数据统计分析工具有哪些
  • 网站认证是什么抖音账号权重查询
  • 镇江高端网站建设广西南宁市有公司网站设计
  • 免费ppt模板下载医院赣州seo公司
  • 企业vi设计公司哪家好seo 的作用和意义
  • 邢台市的做网站制作公司广州百度推广代理公司
  • 自己的网站怎么做seo自己建网站怎么建
  • 网站登录系统企业网站推广有哪些方式