How to view a file on the server in JBoss

I need some ideas on how I can best solve this problem.

I have a JBoss Seam application running on JBoss 4.3.3 What a small part of this application does is generate html and pdf document based on Open Office template.

The files that were generated were placed inside / tmp / on the filesystem. I tried with System.getProperties ("tmp.dir") and some other parameters and they always return $ JBOSS_HOME / bin I would like to select the path $ JBOSS_HOME / $ DEPLOY / myEAR.ear / myWAR.war / WhateverLocationHere /

However, I don't know how I can programmatically select the path without specifying an absolute path, or by setting $ JBOSS_HOME and $ DEPLOY.

Anybody know how I can do this?

Second question; I want to view these generated files easily. Either JavaScript or whatever is the easiest way. However, JavaScript cannot access the file system on the server, so I cannot open the file with JavaScript.

Any easy solutions out there?
0


source to share


5 answers


Not sure how you create PDFs, but if possible, run the IO drive together, seal the PDF content in byte[]

and flush it to the user in the servlet by setting the mime type to application/pdf

* which responds to the URL that is referenced in your client or dynamically set <div>

to javascript. You probably end up in memory anyway, and in addition to skipping I / O, you don't have to worry about deleting tmp files when you're done browsing.



***** I think this is correct. We need to look for him.

+1


source


Not sure if I fully understand what you are trying to achieve, but I will try anyway:

My guess is that your ultimate goal is to make some files (PDF, HTML) available to end users through a web application.

In that case, why doesn't Apache serve these files to end users, so you only need your JBOSS application to find out the directory path that maps to the Apache virtual host.



So create a file and save it as /var/www/html/myappfiles/tempfile.pdf (the folder your app knows in) and then provide http://mydomain.com/myappfiles (Apache virtual host) for your users ... The rest will be done by the web server.

You will need to set an environment variable or system property for your application to know where your folder is (/ var / www / html / myappfiles / in this example).

Hope I haven't been away :)

+1


source


  • I agree with Peter (yo Pete!). Move the directory outside the WAR and set an environment variable to indicate this. Read this post by Jacob Orshalik on how to set up environment variables in Seam:

  • In terms of PDF previews, take a look at how Google Docs handles PDF previews - it displays them as an image. For this with Java check out Sun's PDF Renderer .

+1


source


I'm not sure if this works in JBoss if you want the path in the WAR archive, but you can try using ServletContext.getRealPath (String) .

However, I personally do not want the generated files to be inside my deployed application; instead I would set up an external data directory with something like$JBOSS_HOME/server/default/data/myapp

0


source


  • First, most platforms use java.io.tmpdir

    a temporary directory to install. Some servlet containers override this property to be something under their tree. Why do you need to write a file?
  • Second, I agree with Nicholas: after generating the pdf on the server side, you can create a url that sends the file to the browser when clicked. If you are using a MIME type application/pdf

    , the browser has to do something with it.
0


source







All Articles