problems with servlet-mapping url-pattern lbrtchx

A

Albretch

I have compiled my servlets and tested them via the invoker servlet

http://localhost:8080/myapp/servlet/myserv06

Now I need for this servlet to be accessed under the url

http://localhost:8080/book00/chap02/section06/

I have tried a number of changes to the
<servlet-mapping><url-pattern>
section of the file web.xml

$TOMCAT_HOME/webapps/myapp/WEB-INF/web.xml

How can you use an arbitrary url after you have tested your servlets?

As I understood it you must:

1._ Make sure the invoker servlet has been commented out

2._ use the <web-app><servlet-mapping><url-pattern> section of the
web.xml file to set the url-pattern this servlet is invoked under, or
am I missing something here?

My web.xml file looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>Book Section 06</display-name>
<description>Book Section 06</description>
<servlet>
<servlet-name>myserv06</servlet-name>
<servlet-class>myserv06</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>myserv06</servlet-name>
<url-pattern>/book00/chap02/section06/</url-pattern>
</servlet-mapping>
</web-app>
 
W

Wendy S

Have you moved the entire context over to /path/to/tomcat/webapps/book00
instead of /path/to/tomcat/webapps/myapp? That part right after
localhost:8080 is _usually_ the name of the context, which usually
corresponds to the directory name under 'webapps'. You can change it, but
it's done when you deploy the webapp. If you're just letting Tomcat
magically "find" it with no other action on your part, then the URL will
have that directory name in it. Or if you put everything under the ROOT
webapp, then you can get rid of the context name in the URL.

How did you deploy the "new" version of your webapp?

Ditch the invoker servlet, even for testing, and package your code.

This would mean visiting http://localhost:8080/myapp/book00/chap02/section06
based on your example above. (Note the 'myapp' part that you were missing,
unless you've made this your root webapp.)

(Wouldn't you just want a "Book" servlet that takes the book#, chapter# and
section# as parameters? Are you going to map every single section
separately?)
 
W

William Brogden

Albretch said:
I have compiled my servlets and tested them via the invoker servlet

http://localhost:8080/myapp/servlet/myserv06

Now I need for this servlet to be accessed under the url

http://localhost:8080/book00/chap02/section06/

I have tried a number of changes to the
<servlet-mapping><url-pattern>
section of the file web.xml

$TOMCAT_HOME/webapps/myapp/WEB-INF/web.xml

How can you use an arbitrary url after you have tested your servlets?

As I understood it you must:

1._ Make sure the invoker servlet has been commented out

2._ use the <web-app><servlet-mapping><url-pattern> section of the
web.xml file to set the url-pattern this servlet is invoked under, or
am I missing something here?

My web.xml file looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>Book Section 06</display-name>
<description>Book Section 06</description>
<servlet>
<servlet-name>myserv06</servlet-name>
<servlet-class>myserv06</servlet-class>

Better put your servlet in a package, make sure the class is in a directory
that reflects the package.
Otherwise Tomcat may not find it.
 

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,175
Latest member
Vinay Kumar_ Nevatia
Top