Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SpringMVC中获得资源文件夹的正确路径?_Spring_Spring Mvc - Fatal编程技术网

如何在SpringMVC中获得资源文件夹的正确路径?

如何在SpringMVC中获得资源文件夹的正确路径?,spring,spring-mvc,Spring,Spring Mvc,嗯,我正在使用SpringMVC开发一个应用程序,我必须在我的资源文件夹中存储一些图片,我需要在我的计算机上使用正确的路径,部署应用程序后,我尝试了很多方法,但似乎都不起作用 这是我的配置和我的尝试 servlet-context.xml <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframe

嗯,我正在使用SpringMVC开发一个应用程序,我必须在我的资源文件夹中存储一些图片,我需要在我的计算机上使用正确的路径,部署应用程序后,我尝试了很多方法,但似乎都不起作用

这是我的配置和我的尝试

servlet-context.xml

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

                        <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

                        <!-- Enables the Spring MVC @Controller programming model -->
                        <annotation-driven />

                        <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
                        <resources mapping="/resources/**" location="/resources/" />
                        <resources mapping="/images/**" location="/images/" />  

                        <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
                        <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                            <beans:property name="prefix" value="/WEB-INF/views/" />
                            <beans:property name="suffix" value=".jsp" />
                        </beans:bean>

                        <context:component-scan base-package="com.hpcdg.quality" /> 



                    </beans:beans>
当我显示路径时:我得到一些关于工作区元数据的信息,我需要的是直接进入我的应用程序的webapp中的resources文件夹


任何帮助都将不胜感激。

使用
新的类路径资源(“images\u Emp”+File.separator+this.GenerateName(8)+.png”)

File.separator
使路径平台独立

                             if (!file.isEmpty()) {
                                    try {
                                        mod.addAttribute("objet", resourceLoader.getResource("/resources/images_Emp/"+this.GenerateName(8)+".png").getFile());
                                        System.out.println(resourceLoader.getResource("/resources/images_Emp/"+this.GenerateName(8)+".png").getFile());
                                        file.transferTo(resourceLoader.getResource("/resources/images_Emp/"+this.GenerateName(8)+".png").getFile());

                                    } catch (Exception e) {
                                        throw new RuntimeException("Product Image saving failed", e);
                                    }
                               }

                            return "/QL/Ajouts";
                        }