English 中文(简体)
展示java应用环境外的图像。
原标题:Displaying images from outside of java application context.
  • 时间:2012-04-14 18:20:54
  •  标签:
  • java
  • image

这是使用Windows 7平台上的当地java服务器测试文档上载功能的问题。 由于问题随着Marko的投入而演变,我编辑了这个问题,这样,那些面临同样挑战的人不会浪费时间来了解演变的细节并尽快得出结论。

The challenge was to direct uploaded file to a folder outside of the WAR structure and successfully read it from there. For example: upload an image into c:/tmp/ and then redirect to a confirmation page that displays the image <img src="c:/tmp/test.jpg" />. The upload worked but image would not be displayed. And based on Marko s input, this makes sense because browser sitting at localhost will refuse to load anything from local disk structure using c:. Maybe these are security considerations similar to those with file input control where we cannot set a default path...

The following tag will work in a local establishing .html file but when pasted into a jsp, it得起工作。 而不同的是,浏览器利用当地幽灵进入垃圾场。

<img src="c:/tmp/test.jpg" />

<>Solutions

我认为,马尔科的回答在很大程度上界定了需要做些什么。 虽然我没有采取这种做法,但显然这是这样做的更好方法,我会接受,作为答案。 感谢 Marko!

对于那些不希望安装网络服务器并愿意用黑板生活的人,我已经做了些什么。 同样,我不想把档案上载到我的追回被盗资产结构中,因为当时我需要记住,在向服务器进行部署之前就清除了这一夹子。 但是,这一载荷仍需要能够使用,因此,我简单地创建了另一个 du子项目,并将这一载荷放在其网页上。 这是为了我的当地测试的目的。 唯一的核心是,在上载档案后,我需要更新Eclipse的“清米”项目。

config.properties

#for uploading files
fileUploadDirectory=C:/javawork/modelsite/tmp/WebContent

#for building html links
publicFileServicePrefix=http://localhost:8080/tmp

<img src="http://localhost:8080/tmp/test.jpg" />  // this works - tmp is the name of my dummy project.
最佳回答

如果你在字面上引用一下投向浏览器的超文本(你通过“维生源”获得的超文本),那么与 Java毫无关系。 浏览器是解释这些联系的人。 如果他们不装货,问题就属于浏览器/档案系统。

<>>>>>

根据你的补充诊断结果,我的结论是,浏览器(表面上!)如果从一个因特网URL的超文本档案中查阅,即使URL是 localhost,也拒绝从你的当地磁盘上装载任何东西。

UPDATE 2

(删除,不相关)

UPDATE 3

但是,你处理上载到服务器的档案,这无疑不会像你的解决办法——档案存放在服务器的当地档案系统上,而不是客户。 这种事情可以在阿帕奇吉普里特方案服务器一级处理——为静态内容保留一个URL部分,并配置一个基本目录,用于固定内容。 即使你在当地操作服务器,在你测试的同一机器上,你仍然需要通过网络接口。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签