Spring mvc 映射到外部映像文件夹不工作(<;mvc:resources>;)
我想将我的图像外包到spring项目文件夹之外。经过一些研究,我发现mvc:resources标签似乎是满足我需求的完美解决方案 app servlet.xmlSpring mvc 映射到外部映像文件夹不工作(<;mvc:resources>;),spring-mvc,resources,servlet-mapping,Spring Mvc,Resources,Servlet Mapping,我想将我的图像外包到spring项目文件夹之外。经过一些研究,我发现mvc:resources标签似乎是满足我需求的完美解决方案 app servlet.xml xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven/>
<mvc:resources mapping="/pics/**" location="file:/c:/Tomcat_6/webapps/external_resources/" order="0" />
xmlns:mvc=”http://www.springframework.org/schema/mvc"
xsi:schemaLocation=”http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
JSP调用:
<img src="<c:url value="/pics/test.png"/>" />
“/>
我不知道为什么这对我不起作用
几个小时后,我读到删除以下行可以解决问题,但什么也没发生
<bean id="viewMappings" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property value="true" name="alwaysUseFullPath"></property>
<property name="defaultHandler">
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
</property>
<property name="order" value="1"/>
</bean>
也在变化
<servlet-mapping>
<servlet-name>onlinecatalog</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
在线目录
*.htm
到
在线目录
/
没有帮助。您可以像这样使用基于java的配置(在linux中) } 现在,您可以从tmpFiles文件夹访问外部文件。 在windows中,您可能需要图像路径作为
imagePath="file:c:/Tomcat_6/webapps/external_resources/";
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String rootPath = System.getProperty("user.home");
String imagePath = "file:"+rootPath + File.separator + "tmpFiles/"; //absolute path of the directory
System.out.println(imagePath);
registry.addResourceHandler("/resources/**").addResourceLocations("resources/");
registry.addResourceHandler("/tmpFiles/**").addResourceLocations(imagePath);
imagePath="file:c:/Tomcat_6/webapps/external_resources/";