Questions about serving static files from a servlet
Posted
by Geo
on Stack Overflow
See other posts from Stack Overflow
or by Geo
Published on 2010-05-28T15:53:54Z
Indexed on
2010/05/28
16:02 UTC
Read the original article
Hit count: 281
I'm very new to servlets. I'd like to serve some static files, some css and some javascript. Here's what I got so far:
- in web.xml:
<servlet>
<description></description>
<display-name>StaticServlet</display-name>
<servlet-name>StaticServlet</servlet-name>
<servlet-class>StaticServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StaticServlet</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>
I'm assuming in the StaticServlet
I'd have to work with request.getPathInfo
to see what was requested, get a mime type, read the file & write it to the client.
If this is not the way to go, or is not a viable way of doing things, please suggest a better way.
I'm not really sure where to place the static
directory, because if I try to print new File(".")
it gives me the directory of my Eclipse installation.
Is there a way to find out the project's directory?
© Stack Overflow or respective owner