Mapping urls to a jsp

I have a directory with some schema files in that I wanted to list for people to see. The old tomcat would list them if you went to the directory e.g. http://www.dasregistry.org/validation1.6/ there were a few forums where various answers to how to do this came up top in google, but they weren’t very simple. The simplest being to create a servlet to redirect to the jsp from your desired urls, simple but not very quick. I knew there had to be a quicker way as jsps are compiled into servlets anyway!

I found an article here http://www.xyzws.com/JSPfaq/how-to-config-a-jsp-file-in-webxml/2 which is what I wanted and it’s pretty easy.

<servlet>
<servlet-name>myjsp</servlet-name>
<jsp-file>/myjsp.jsp</jsp-file>
<init-param>
<param-name>hello</param-name>
<param-value>test</param-value>
</init-param>
</servlet>
 
<servlet-mapping>
<servlet-name>myjsp</servlet-name>
<url-pattern>/myjsp</url-pattern>
</servlet-mapping>

so for my directory listing url I used these mappings to allow access through the directory with and without the last slash:

<servlet>

<servlet-name>relaxng1.6</servlet-name>

<jsp-file>/validation1.6/relaxng.jsp</jsp-file>

</servlet>

 

<servlet-mapping>

<servlet-name>relaxng1.6</servlet-name>

<url-pattern>/validation1.6</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>relaxng1.6</servlet-name>

<url-pattern>/validation1.6/</url-pattern>

</servlet-mapping>
Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: