简体   繁体   English

刷新SparkJava提供的静态文件

[英]Refresh static files served by SparkJava

I'm doing a project using Spark Java. 我正在使用Spark Java做一个项目。 On the server side, some images are created and I want them to be available in the client. 在服务器端,创建了一些图像,我希望它们在客户端中可用。 Since I have a static content directory, after creating the image on the server side, I place it in that directory. 由于我有一个静态内容目录,在服务器端创建映像后,我将它放在该目录中。 However, this file is not available unless I reboot the server. 但是,除非我重新启动服务器,否则此文件不可用。 I guess there must be a way to refresh the static directory file for Spark Java on runtime so that requests of on-runtime created images can be fulfilled. 我想必须有一种方法可以在运行时刷新Spark Java的静态目录文件,以便可以实现运行时创建的映像请求。 Right? 对?

Thanks! 谢谢!

The documentation says: 文件说:

If you use staticFiles.location(...) , meaning you keep your static files in the classpath, static resources are copied to a target folder when you build your application. 如果使用staticFiles.location(...) ,意味着将静态文件保留在类路径中,则在构建应用程序时staticFiles.location(...)静态资源复制到目标文件夹。 This means you have to make/build your project in order to refresh static files. 这意味着您必须创建/构建项目才能刷新静态文件。 A workaround for this is to tell Spark to read static files from the absolute path to the src-directory. 解决方法是告诉Spark从src-directory的绝对路径读取静态文件。

So use staticFiles.externalLocation() instead. 所以请改用staticFiles.externalLocation()

我已经通过将png编码为Base 64并将其作为响应发送给客户端来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 重新启动后的Sparkjava静态文件404 - Sparkjava static files 404 after restart 在SparkJava中为静态文件添加`before`过滤器 - Add `before` filter for static files in SparkJava 在Windows中使用tomcat 7在Spring MVC中提供静态文件,但在Linux中不提供静态文件 - Static files are served in Spring MVC with tomcat 7 in Windows, but not on Linux 在appengine-web.xml中使用静态文件声明时,JavaScript文件将作为HTML文件提供 - Javascript files are served up as HTML files when using static-files declaration in appengine-web.xml sparkjava(java webframe)如何自动刷新页面 - How does sparkjava(java webframe) auto refresh page 无法提供JMOL pdb文件 - JMOL pdb files not being served 升级到 Spring 4.3.0,静态 JS 文件现在作为“application/octet-stream”而不是 Spring 4.2.6 中的“application/javascript” - Upgraded to Spring 4.3.0 and static JS files are now served as 'application/octet-stream' instead of 'application/javascript' as in Spring 4.2.6 Spring MVC 无法提供静态资源 - Static resource cannot be served with Spring MVC 已解决:Static 资源 Springboot (2.6.3) 和 Vaadin (23.2.5) 未在生产中提供 - Solved : Static Resources Springboot (2.6.3) and Vaadin (23.2.5) not served in production Springboot 2.1.7.RELEASE中没有提供静态内容 - Static content not getting served in Springboot 2.1.7.RELEASE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM