Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.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
Java Spring框架和tomcat-如何启用到文件夹的以下符号链接?_Java_Spring_Spring Mvc_Tomcat6_Symlink - Fatal编程技术网

Java Spring框架和tomcat-如何启用到文件夹的以下符号链接?

Java Spring框架和tomcat-如何启用到文件夹的以下符号链接?,java,spring,spring-mvc,tomcat6,symlink,Java,Spring,Spring Mvc,Tomcat6,Symlink,我有一个用Java+spring框架编写的web应用程序。使用的应用服务器是tomcat。假设web应用程序名为“sample webapp”。如果我在示例webapp/resources/下创建一个符号链接,如下所示- ls-l …/sample webapp/resources/temp csv location->/tmp/csv location 这里的“临时csv位置”是一个符号链接 现在,如果我在jsp页面中引用这个目录中的一个文件,比如 <a href="http:

我有一个用Java+spring框架编写的web应用程序。使用的应用服务器是tomcat。假设web应用程序名为“sample webapp”。如果我在示例webapp/resources/下创建一个符号链接,如下所示-

ls-l

…/sample webapp/resources/temp csv location->/tmp/csv location

这里的“临时csv位置”是一个符号链接

现在,如果我在jsp页面中引用这个目录中的一个文件,比如

<a href="http://localhost:8080/sample-webapp/resources/temp-csv-location/test.csv">Click</a>

它给我一个404错误。我确认test.csv文件存在于/tmp/csv location/中。我也确认了权限。在tomcat的普通用法中,我们可以在context.xml中添加“allowLinking=true”


在spring框架中有没有办法做到这一点?

解决您问题的另一种通用解决方案是编写一个Servlet来处理所有与启动路径有关的请求,然后Servlet将通过解析其路径来处理文件的提供

为了设置Servlet,您必须将其放在web.xml中

<filter>
    <filter-name>csvFileDownloadServlet</filter-name>
    <filter-class>edu.sharif.resource.CSVFileDownloadServlet</filter-class>
</filter>
<filter-mapping>
    <filter-name>csvFileDownloadServlet</filter-name>
    <url-pattern>/resources/temp-csv-location/*</url-pattern>
</filter-mapping>

csvFileDownloadServlet
edu.sharif.resource.CSVFileDownloadServlet
csvFileDownloadServlet
/资源/临时csv位置/*
然后您应该编写edu.sharif.resource.CSVFileDownloadServlet类。您可以通过简单的搜索找到解决此问题的几种实现方法,例如: