servlet mapping problems

Discussion in 'Java' started by joel s, Nov 3, 2003.

  1. joel s

    joel s Guest

    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.
    joel s, Nov 3, 2003
    #1
    1. Advertising

  2. joel s

    Wendy S Guest

    joel s wrote:

    > 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
    <servlet-mapping> for JSP's.)

    > 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.

    --
    Wendy in Chandler, AZ
    Wendy S, Nov 4, 2003
    #2
    1. Advertising

  3. joel s

    joel s Guest

    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

    Wendy S <> wrote in message news:<ZfFpb.3249$7B2.2948@fed1read04>...
    > joel s wrote:
    >
    > > 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
    > <servlet-mapping> for JSP's.)
    >
    > > 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.
    joel s, Nov 4, 2003
    #3
  4. joel s

    Ben_ Guest

    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 :).
    Ben_, Nov 4, 2003
    #4
  5. joel s

    Sudsy Guest

    joel s wrote:
    > 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>/jsp/WebRoll3.jsp</welcome-file>

    > </welcome-file-list>
    >
    Sudsy, Nov 4, 2003
    #5
  6. joel s

    Wendy S Guest

    joel s wrote:
    > 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
    ___?"

    --
    Wendy in Chandler, AZ
    Wendy S, Nov 5, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Albretch
    Replies:
    2
    Views:
    923
    William Brogden
    Jul 11, 2003
  2. Fran Cotton

    Servlet URL Mapping Evil!

    Fran Cotton, Jul 25, 2003, in forum: Java
    Replies:
    0
    Views:
    3,347
    Fran Cotton
    Jul 25, 2003
  3. Fran Cotton

    Servlet Mapping - What's the point?

    Fran Cotton, Aug 7, 2003, in forum: Java
    Replies:
    3
    Views:
    561
    Tor Iver Wilhelmsen
    Aug 8, 2003
  4. joel s
    Replies:
    0
    Views:
    291
    joel s
    Nov 3, 2003
  5. circuit_breaker
    Replies:
    2
    Views:
    1,966
    Jack Jia
    Apr 4, 2004
Loading...

Share This Page