servlet mapping problems

J

joel s

Hey guys/gals. My first attempted at servlet mapping flubbed.

Background:
A friend at work suggested I store my source in webapps\wbrl\jsp
So I have Tomcat\webapps\wbrl\jsp\WebRoll.jsp

Currently I type http://localhost:8080/wbrl/jsp/WebRoll3.jsp

This brings up my application successfully.

I would like to be able to type http://localhost:8080/wbrl and have
it bring up my web page.

So I tried to change the web.xml, but it doesnt work.

<servlet>
<servlet-name>WebRoll3</servlet-name>
<servlet-class>WebRoll3</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>WebRoll3</servlet-name>
<url-pattern>/wbrl/*</url-pattern>
</servlet-mapping>

<url-pattern>/wbrl/*</url-pattern> causes "Wrapper cannot find servlet
class WebRoll3 or a class it"

How do i fix this? Do I use filter mapping? I got totally lost in the
filter mapping explanation.
 
W

Wendy S

joel said:
Hey guys/gals. My first attempted at servlet mapping flubbed.

You don't have a servlet, there's nothing to map. (Well, technically JSP's
do get converted to Servlet code, but you don't use <servlet> and
Currently I type http://localhost:8080/wbrl/jsp/WebRoll3.jsp
This brings up my application successfully.
I would like to be able to type http://localhost:8080/wbrl and have
it bring up my web page.

Put it in the 'Welcome Files' list and Tomcat will redirect to that .jsp
when it receives a request with no filename specified. You posted that bit
of web.xml in your other message, but it still lists index.html/index.jsp
instead of the file you want Tomcat to serve up.
How do i fix this? Do I use filter mapping? I got totally lost in the
filter mapping explanation.

You'd first have to write a class that extends Filter. I don't think that's
what you want for this problem.
 
J

joel s

Ok, well, I added <welcome-file>WebRoll3.jsp</welcome-file>
<servlet>
<servlet-name>WebRoll3</servlet-name>
<servlet-class>WebRoll3</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WebRoll3</servlet-name>
<url-pattern>/wbrl/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>WebRoll3.jsp</welcome-file>
</welcome-file-list>

It brings me to:

http://localhost:8080/wbrl/
Directory Listing For /
-----------------------------------------------------
Filename Size Last Modified
jsp/

Then I have click "jsp/" to get to the welcome page

How do I get it to do what I want which is type:
"http://localhost:8080/wbrl"

and have it bring me to:

http://localhost:8080/wbrl/jsp/WebRoll3.jsp

Regards, Joel S
 
B

Ben_

You get a directory listing because there is not default document in /wbrl.

Place a WebRoll3.jsp in /wbrl to redirect to the place you like (with
response.sendRedirect for example). Of course you may want to add a
'welcome-file' entry with 'index.jsp' (which a bit more standard :).
 
S

Sudsy

joel said:
Ok, well, I added <welcome-file>WebRoll3.jsp</welcome-file>
<servlet>
<servlet-name>WebRoll3</servlet-name>
<servlet-class>WebRoll3</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WebRoll3</servlet-name>
<url-pattern>/wbrl/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>WebRoll3.jsp</welcome-file>
 
W

Wendy S

joel said:
Ok, well, I added <welcome-file>WebRoll3.jsp</welcome-file>
It brings me to:
Directory Listing For /
Then I have click "jsp/" to get to the welcome page
How do I get it to do what I want which is type:
"http://localhost:8080/wbrl"
and have it bring me to:
http://localhost:8080/wbrl/jsp/WebRoll3.jsp

Without any path given, it expected to find your file in the root of the
webapp directory. It didn't, so it gave up and showed you the contents of
the directory. You need this instead:

<welcome-file>jsp/WebRoll3.jsp</welcome-file>

(Sudsy, you have a leading slash, but SRV.9.10 says "The welcome file list
is an ordered list of partial URLs with no trailing or leading /.")

Joel, you might want to download the Servlet Specification and at least flip
through it so you know what's there. The behavior you're trying to get is
covered chapter 9 of the Java Servlet Specification Version 2.3. This
document explains what your Servlet container is required to do for you,
which is useful when you're wondering, "Why won't it ___?" and "How do I
___?"
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top