2

I'm using Glassfish/JSF. Is it possible to host static files from disk? I need to generate xml file and save it somewhere on disk so it could be available as http://domain.com/file.xml

I need similar functionality to apache/php where I can save file to /public_html and it is automatically available.

karolkpl
  • 2,189
  • 10
  • 39
  • 60

3 Answers3

1

There is a folder named docroot inside the domain folder: domain-dir/docroot. Whatever you put there, will be published as static content.

jgomo3
  • 1,153
  • 1
  • 13
  • 26
1

I think you should try out Virtual directory. Basically, you only need to create a Virtual directory which is mapped to a folder on your hard-disk. After that, you can access all files in that folder directly from the URL as desired.

Mr.J4mes
  • 9,168
  • 9
  • 48
  • 90
-1

The Virtual Directory idea is good, but this problem can typically be solved easy enough by defining a custom servlet. No need for an additional component at all.

<servlet>
  <servlet-name>Mah Servlet</servlet-name>
  <servlet-class>org.mahorg.MahServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>Mah Servlet</servlet-name>
  <url-pattern>*.xml</url-pattern>
</servlet-mapping>

Then you just write a servlet that can do the following things...

1. Determine filename and folder location looking at request context path
2. Get bytes of file using easy tool like Apache Commons IO.
3. Put bytes into response stream
4. Set response header to XML mime type
5. Response complete

Don't forget the obligatory security concerns and file permissions etc...

maple_shaft
  • 10,435
  • 6
  • 46
  • 74
  • This is bad advice. Instead configure Glassfish or Tomcat to serve the static content. Writing your own CustomServlet is a recipe for security holes and lost performance. – Leonhard Printz Mar 23 '20 at 15:49