本文介绍了如何刷新Java Web Application中的静态资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一种动态存储数据并在生成或上传时显示数据的应用程序。但问题是当我上传任何图像,然后它应该显示。它的路径也是完全定义的,但是直到我刷新Eclipse中的整个应用程序,它保持不变。
所以要更新应用程序,我必须刷新它。



我的应用程序是基于Java的,并且正在使用JSP和Servlet。是否有可用于更新或刷新应用程序的代码?



现在我正在通过右键单击 - >刷新或直接F5来执行。



或者假设我想创建目录,那么我将在哪里创建它,这将很容易访问,无需刷新。



当我托管我的应用程序,那么哪个地方更好地存储数据?
我知道它在网络应用程序之外,但是任何特定的地方?因为没有驱动器,所以我如何创建或制作目录并访问我的代码。

解决方案

我想你需要看进入Eclipse中的工作区重新选择(从Eclipse版本3.7.x可以使用)。您可以在首选项>常规>工作区中启用它,然后选择刷新访问,或者根据需要,您可以更改为所需的任何设置。 p>

静态内容的位置是如果放在项目本身的范围之外,最好。也许您的服务器上的其他目录(无论是任何目录)。



我可以分享我通常认为是个人工作的不同应用程序的趋势。我们有一个单独的tomcat服务器,它托管了所有静态内容(所有媒体),我们的Web应用程序在安全网络中访问了静态服务器(如它所命名的)。所有命中静态内容只能通过我们的应用服务器进行,​​因此所有的直接命中都被拒绝或不被接受。



修改



我建议使用绝对路径
并且在Windows环境
上,您将需要使用驱动器lletter
并将路径指定为X:\some\path
如果要隐藏您的信函驱动器
到期明显的安全原因
我可以建议另一个想法



想法1 :制作一个单独的驱动器(让它称为驱动器F)和制作一个名为static的文件夹。然后在您的应用程序中,您只需使用此路径将所有请求转发到文件上传(F:\static ......)。我建议从属性文件中加载目录名称,而不是在代码中硬编码。



想法2 :如果你不能单独驱动器,然后在同一驱动器的根目录(C:\static)上创建一个名为static的目录。创建一个用户组,并给予该驱动器的读/写权限,并在所有其他驱动器上撤销此用户的写入权限(以防万一有人混淆此用户组)。接下来做同样的事情,就是指定这个路径到你的应用程序。有一点是,您必须使用特定的用户组来运行应用程序,以确保您可以实现安装的权限安全。


I am developing an application that stores data dynamically and displays it as it is generated or uploaded. But the problem is when I am uploading any image then it should be displayed. It's path is also defined perfectly but until I refresh the whole application in eclipse it remains unchanged.So to update application, I have to refresh it.

My application is Java based and is useing JSP and Servlet. Is there any code that can be used to update or refresh the application?

Right now I am doing it by right click -> refresh or directly F5 it.

Or suppose I want to create directory then where will I have to create it that will be accesses easily without refresh.

When I'll host my application then which place is better for to store data?I know it's outside the web app but any specific place? Because there is no drive so how can I create or make directory and access that one in my code.

解决方案

I think you need to look into the workspace re-fresh option in Eclipse ( was made available from Eclipse version 3.7.x ). You can enable it in Preferences > General > Workspace and select Refresh on access or as per need you can change to whatever setting you require.

The location of static content is best if placed outside of the scope of the project itself. Maybe some other directory on your server ( be it any directory ).

I can share what I have normally seen as a trend in different applications that I have personally worked on. We had a separate tomcat server that just hosted all static content ( all media ) and our web application accessed that static-server (as it was named) within a secured network. All hits to static content could only be made via our application server and thus all direct hits were either rejected or not entertained at all.

Edit

I would suggest using a an absolute pathand on windows environmentyou will HAVE to use the drive lletterand specify the path as X:\some\pathif you want to hide your letter drivedue to obvious security reasonI can suggest another idea

Idea 1 : Make a separate drive (lets call it drive F) and make a folder with the name of "static". Then in your application , you just forward all requests to file uploads using this path ( F:\static......) . I would advise loading the directory name from a property file instead of hard-coding it in your code

Idea 2 : If you cant make a separate drive, then make a directory namely "static" on the root of same drive ( C:\static ) . Make a user group and give him read/write permissions on this drive and revoke writing permissions from this user on all other drives ( just in case someone messes up with this user-group). Next do the same thing as above i.e specify this path into your application. One thing is that you would have to run your application with that specific user-group to ensure that the permissions security you have setup can be implemented.

这篇关于如何刷新Java Web Application中的静态资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 10:43