简体   繁体   中英

How can I externalize a PDF from a Java EE application?

I have a Java EE application, running under WebLogic 10.3.5 and Java 6. I used to have a pdf help file, embedded in my war file, but I need to extract it from there and put it in an external directory (it can be in my same WebLogic domain directory).

I tried to put it in my WebLogic domain and then to < a href > it, but it seems that browsers have limitation and for security reason will not allow to download local file with a href or javascript.

This used to work only on a static HTML file saved on my computer but one the HTML page is deployed on the server, it seems not be possible.

Any idea how I can externalize my help.pdf file from my war file?

Although some application servers allow a Java EE app to reference a file outside the web container, in reality, your web app shouldn't have any knowledge about anything outside the web container, and as you have mentioned, it is indeed a huge security concern.

Depending on what you are trying to accomplish with this PDF file, if you merely want to expose this file on the web, do what @duffmo said and it will work fine. If you want the flexibility to modify this PDF file frequently without recreating the war file again and again, you may want to consider hosting this PDF file in some HTTP web server (Apache2, IIS, etc) and now you reference that link from your web app.

@limc is right

you should put this static file outside of Weblogic altogether as a file on an Apache web server

However, in Weblogic there is a feature of virtual directory mapping which allows you to declare a folder outside of the weblogic domain as a content store for any static stuff.

http://docs.oracle.com/cd/E11035_01/wls100/webapp/weblogic_xml.html#wp1039396

This entry goes in WEB-INF/weblogic.xml

<virtual-directory-mapping>      
<local-path>c:/usr/mypdfs</local-path>      
<url-pattern>/pdf/*</url-pattern>      
</virtual-directory-mapping>

You need to put it at the root of your web context, in exactly the same place as HTML pages. Your web server will be able to find it there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM