jsps, images and a catch-all in the web.xml file

S

subscriptions

I'm writing a JSP/Servlet web-app for transforming mnemonics into URLs,
similar to what http://tinyurl.com does. In other words, if the
mnemonic "xyz" points to http://google.com, then entering
http://example.com/xyz (where example.com is my website) would
automatically redirect to Google.

I figured I could use a catch-all url map in order to analyze the
indicated mnemonic. But how do I access the static elements of the
web-app? For instance, say I have a gif on the site, icon.gif. How
could I reference it? I could use an image servlet, mapped so:

<servlet>
<servlet-name>imageLoader</servlet-name>
<servlet-class>com.example.ImageLoaderServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>imageLoader</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>

but if the image is in the base directory, loading it via
HttpServletRequest.getRequestDispatcher(String) results in an endless
loop.

For text files I've been using a mapping like:

<servlet>
<servlet-name>stylesCss</servlet-name>
<jsp-file>/styles.jsp</jsp-file>
</servlet>

<servlet-mapping>
<servlet-name>stylesCss</servlet-name>
<url-pattern>styles.css</url-pattern>
</servlet-mapping>

which works just fine, but is a total hack. What's the preferred way
of doing something like this?

Thanks,

Walter Gildersleeve
Freiburg, Germany
 
A

Andrea Desole

which works just fine, but is a total hack. What's the preferred way
of doing something like this?

have you considered a servlet filter? That looks like a good place for
your catch-all url map
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top