jsf/glassfish hosting static files

二次信任 提交于 2019-12-24 02:52:49

问题


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.


回答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.




回答2:


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...




回答3:


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



来源:https://stackoverflow.com/questions/8678668/jsf-glassfish-hosting-static-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!