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

年前做网站的好处远洋国际一期官方网站建设

年前做网站的好处,远洋国际一期官方网站建设,网站空间送域名,做企业网站制作上一篇我们详细解释了一下SrpingMVC的执行流程以及一些默认的配置#xff0c;在Spring的思想中#xff0c;就是默认大于配置。今天我们来详细的研究一下DispatcherServlet的url-pattern配置。 一、DispatcherServlet的url-pattern配置在没有特别要求的情况下#xff0c;Spri…上一篇我们详细解释了一下SrpingMVC的执行流程以及一些默认的配置在Spring的思想中就是默认大于配置。今天我们来详细的研究一下DispatcherServlet的url-pattern配置。 一、DispatcherServlet的url-pattern配置在没有特别要求的情况下SpringMVC的中央调度器DispatcherServlet的url-pattern常使用后缀匹配方式进行配置如*.do、*.action注意这里的url-pattern不能写/*因为DispatcherServlet会将向JSP的动态页面跳转请求也当作为普通的Controller来处理。中央调度器在调用处理器映射器来为其查找相应的处理器时肯定找不到。所以在这种情况下所有的JSP页面跳转都会变为404。最好也不要写成/因为DispatcherServlet会将向静态资源的请求当作为普通的Controller来处理。如.css、.jpg、.js等。所以静态资源也会变成404。所以建议写成*.do、*.action之类的配置。当然也有一些时候不得不配置成/当开发一些移动端接口采用restful请求时需要配置成/。 二、url-pattern配置为/时静态资源的访问1使用tomcat的默认Servlet解决在web.xml中添加如下代码 servlet-mappingservlet-namedefault/servlet-nameurl-pattern*.js/url-pattern /servlet-mapping 注意上方只处理*.js如果需要大家可以再加几个拦截其它资源。使用该配置只需要配置servlet-mapping即可default的Servlet配置在tomcat的conf/web.xml文件中。如下图 具体的解释在该段代码的上方注释里。 !-- The default servlet for all web applications, that serves static -- !-- resources. It processes all requests that are not mapped to other -- !-- servlets with servlet mappings (defined either here or in your own -- !-- web.xml file). This servlet supports the following initialization -- !-- parameters (default values are in square brackets): -- 该default的servlet对所有的web应用程序生效专门处理静态资源。处理所有没有匹配到servlet mappings的请求 2使用SpringMVC的default-servlet-handler解决在springmvc.xml中添加mvc:default-servlet-handler/。当然添加这个default-servlet-handler时需要对当前xml添加mvc的约束xsd。如下图 最终springmvc.xml如下 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxmlns:txhttp://www.springframework.org/schema/txxmlns:mvchttp://www.springframework.org/schema/mvcxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdmvc:default-servlet-handler/!-- 注册视图解析器 --bean classorg.springframework.web.servlet.view.InternalResourceViewResolverproperty nameprefix value/WEB-INF/jsp/ /property namesuffix value.jsp //bean!-- 注册SpringMVC处理器 --bean id/my.do classcn.wechatbao.controller.MyController/bean /beans 注意default-servlet-handler会对静态资源的访问请求通过handlerMapping映射到默认的Servlet请求处理器DefaultServletHttpRequestHandler类上。而该类最终调用的是Tomcat的defaultServlet来处理的请求。如图 3使用SpringMVC的resources解决在springmvc.xml中添加如下代码mvc:resources location/images/ mapping/images/**/mvc:resources其中的location和mapping为具体的静态资源文件夹大家可以根据具体的项目来定义。注意该方法是在spring3.0.4版本后专门定义的一个静态资源的处理器ResourceHttpRequestHandler类该种配置文件会将所有的静态资源映射到ResourceHttpRequestHandler该类转载于:https://www.cnblogs.com/xinhudong/p/8323857.html
http://www.sadfv.cn/news/107080/

相关文章:

  • 能免费用服务器的网站wordpress游戏代练主题
  • 网站开发和数据库哪个有前途十大邮箱app排行榜
  • 网站建设 报告中国平安网站建设
  • 重庆网站改版手机模拟器
  • dedecms部署两个网站字画网站模板
  • 网站建设 软件开发网站建设哪里
  • 企业网站模板 简洁美食html网页代码模板
  • 常见网站建设公司术语专门做颜料的网站
  • 网站免费建站的方法最好机票网站建设
  • 网站运营有前途吗dede网站源码
  • 酒仙桥网站建设主题资源网站建设作业
  • 专业做网站服务商wordpress水印图片插件
  • 微信网站建设报价单重庆工业设计公司有哪些
  • wordpress企业站网建公司浅谈网站建设的目的和意义
  • 网站制作要学多久网站手机版模板免费下载
  • 网站建设400电话网络工程有限公司
  • 做土司的网站蜂鸟影院高清免费观看
  • 为公司制作网站流量统计是可以查询到网站来路的关键字里出现了不相关的关键词
  • 网站建设的难点推销别人做网站有什么作用
  • 备案网站有哪些资料龙岩网站推广营销
  • 长治哪里做网站移动商城官网 积分兑换
  • 婚纱摄影网站模板源码软文代发平台
  • wordpress好学上海专业的seo推广咨询电话
  • 大庆门户网站手机购买网站源码
  • 服装设计师参考的网站网站开发运营公司
  • 儿童网站模板免费下载网站建设的企业
  • 东莞建设教育网站高端建造品牌影响力不断增强
  • 怎么在国税网站上做实名认证自助建站系统介绍
  • 织梦dedecms医院类网站在线预约挂号插件山西建设网站的公司
  • 智慧团建网站登录平台手机版微软的网站开发软件