SpringMVC-Day6

今天继续开发自己的第一个博客系统。此役在配置过程中遇到了一些问题,目前为止还未完全解决。看来亲自动手做确实不易。

这些问题都是在Spring基础上无法加载静态资源造成的--页面上的jpg和css都没有生效。记得公司的项目中配置了一些default的servlet-mapping,以防止Dispathcer拦截掉了这些请求从而导致静态资源无法访问。我自己试了一下还是没能成功。另外在寻求解决此问题的过程中还遇到的一些问题以及其解决方案,均如下列出。

1.default映射的配置

<servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.js</url-pattern>
        <url-pattern>*.html</url-pattern>
        <url-pattern>*.css</url-pattern>
    </servlet-mapping>


2.试图通过如下配置

 <mvc:resources mapping="/javascript/**" location="/static_resources/javascript/"/>  

 <mvc:resources mapping="/styles/**" location="/static_resources/css/"/>  

 <mvc:resources mapping="/images/**" location="/static_resources/images/"/>

去拦截这些请求。不过mvc的prefix需要在xml的头部配置,先前不太明白这个概念,就只在头部添加了一个链接:

http://www.springframework.org/schema/mvc

后来经过查阅才发现,是有规则的:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"	
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"	
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context"	
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd       
http://www.springframework.org/schema/context  
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc  
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">


首先得为mvc配置xmlns,接下来配置xsi,其中必然是一个解释文件对应一个解释目录。这样才不会报错了。否则会报错:Spring配置文件异常:White spaces are required between publicId and systemId


3.曾试图复制项目重新导入Eclipse,再配置tomcat进行启动。不过当时项目报错,说的事HttpServletRequest这个类无法解析。解决办法就是去tomcat目录的lib文件夹拷贝servlet-api到项目中就可以了。


4.目前网上常常能看到的三种办法都没能解决我目前的问题。不知是不是我使用的Spring4的原因。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值