servlet accessed from url with subdirectory

Discussion in 'Java' started by Steve, Jan 23, 2007.

  1. Steve

    Steve Guest

    I have a servlet that I'd like to access with a url that includes a
    subdirectory; e.g., www.whatever.com/mysubdir/MyServlet (because that
    subdirectory is a protected area with associated jsp's).

    But, I can't seem to get a configuration that will map a request to the
    servlet. I tried the following in web.xml to no avail:

    <servlet>
    <servlet-name>XServlet</servlet-name>
    <servlet-class>XServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>XServlet</servlet-name>
    <url-pattern>/mysubdir/com.whatever.XServlet</url-pattern>
    </servlet-mapping>

    How do I accomplish this?
     
    Steve, Jan 23, 2007
    #1
    1. Advertising

  2. Steve wrote:
    > I have a servlet that I'd like to access with a url that includes a
    > subdirectory; e.g., www.whatever.com/mysubdir/MyServlet (because that
    > subdirectory is a protected area with associated jsp's).
    >
    > But, I can't seem to get a configuration that will map a request to the
    > servlet. I tried the following in web.xml to no avail:
    >
    > <servlet>
    > <servlet-name>XServlet</servlet-name>
    > <servlet-class>XServlet</servlet-class>
    > </servlet>
    > <servlet-mapping>
    > <servlet-name>XServlet</servlet-name>
    > <url-pattern>/mysubdir/com.whatever.XServlet</url-pattern>
    > </servlet-mapping>
    >
    > How do I accomplish this?


    <servlet>
    <servlet-name>XServlet</servlet-name>
    <servlet-class>com.whatever.XServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>XServlet</servlet-name>
    <url-pattern>/mysubdir/XServlet</url-pattern>
    </servlet-mapping>

    would be my guess.

    Arne
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Jan 23, 2007
    #2
    1. Advertising

  3. Steve

    Steve Guest

    Sorry,

    That's what I actually did have. In my editing to remove the real site
    names, etc., I got it backwards. But what you wrote matches the
    format of the code in my web.wml, which doesn't work.

    Steve

    Arne Vajhøj wrote:
    > Steve wrote:
    >> I have a servlet that I'd like to access with a url that includes a
    >> subdirectory; e.g., www.whatever.com/mysubdir/MyServlet (because that
    >> subdirectory is a protected area with associated jsp's).
    >>
    >> But, I can't seem to get a configuration that will map a request to
    >> the servlet. I tried the following in web.xml to no avail:
    >>
    >> <servlet>
    >> <servlet-name>XServlet</servlet-name>
    >> <servlet-class>XServlet</servlet-class>
    >> </servlet>
    >> <servlet-mapping>
    >> <servlet-name>XServlet</servlet-name>
    >> <url-pattern>/mysubdir/com.whatever.XServlet</url-pattern>
    >> </servlet-mapping>
    >>
    >> How do I accomplish this?

    >
    > <servlet>
    > <servlet-name>XServlet</servlet-name>
    > <servlet-class>com.whatever.XServlet</servlet-class>
    > </servlet>
    > <servlet-mapping>
    > <servlet-name>XServlet</servlet-name>
    > <url-pattern>/mysubdir/XServlet</url-pattern>
    > </servlet-mapping>
    >
    > would be my guess.
    >
    > Arne
     
    Steve, Jan 23, 2007
    #3
  4. Steve wrote:
    > Arne Vajhøj wrote:
    >> Steve wrote:
    >>> I have a servlet that I'd like to access with a url that includes a
    >>> subdirectory; e.g., www.whatever.com/mysubdir/MyServlet (because that
    >>> subdirectory is a protected area with associated jsp's).
    >>>
    >>> But, I can't seem to get a configuration that will map a request to
    >>> the servlet. I tried the following in web.xml to no avail:
    >>>
    >>> <servlet>
    >>> <servlet-name>XServlet</servlet-name>
    >>> <servlet-class>XServlet</servlet-class>
    >>> </servlet>
    >>> <servlet-mapping>
    >>> <servlet-name>XServlet</servlet-name>
    >>> <url-pattern>/mysubdir/com.whatever.XServlet</url-pattern>
    >>> </servlet-mapping>
    >>>
    >>> How do I accomplish this?

    >>
    >> <servlet>
    >> <servlet-name>XServlet</servlet-name>
    >> <servlet-class>com.whatever.XServlet</servlet-class>
    >> </servlet>
    >> <servlet-mapping>
    >> <servlet-name>XServlet</servlet-name>
    >> <url-pattern>/mysubdir/XServlet</url-pattern>
    >> </servlet-mapping>
    >>
    >> would be my guess.


    > That's what I actually did have. In my editing to remove the real site
    > names, etc., I got it backwards. But what you wrote matches the format
    > of the code in my web.wml, which doesn't work.


    What error do you get ?

    Arne
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Jan 23, 2007
    #4
  5. Steve

    Steve Guest

    Arne Vajhøj wrote:
    > Steve wrote:
    >> Arne Vajhøj wrote:
    >>> Steve wrote:
    >>>> I have a servlet that I'd like to access with a url that includes a
    >>>> subdirectory; e.g., www.whatever.com/mysubdir/MyServlet (because
    >>>> that subdirectory is a protected area with associated jsp's).
    >>>>
    >>>> But, I can't seem to get a configuration that will map a request to
    >>>> the servlet. I tried the following in web.xml to no avail:
    >>>>
    >>>> <servlet>
    >>>> <servlet-name>XServlet</servlet-name>
    >>>> <servlet-class>XServlet</servlet-class>
    >>>> </servlet>
    >>>> <servlet-mapping>
    >>>> <servlet-name>XServlet</servlet-name>
    >>>> <url-pattern>/mysubdir/com.whatever.XServlet</url-pattern>
    >>>> </servlet-mapping>
    >>>>
    >>>> How do I accomplish this?
    >>>
    >>> <servlet>
    >>> <servlet-name>XServlet</servlet-name>
    >>> <servlet-class>com.whatever.XServlet</servlet-class>
    >>> </servlet>
    >>> <servlet-mapping>
    >>> <servlet-name>XServlet</servlet-name>
    >>> <url-pattern>/mysubdir/XServlet</url-pattern>
    >>> </servlet-mapping>
    >>>
    >>> would be my guess.

    >
    > > That's what I actually did have. In my editing to remove the real site
    > > names, etc., I got it backwards. But what you wrote matches the format
    > > of the code in my web.wml, which doesn't work.

    >
    > What error do you get ?
    >
    > Arne

    I I try to access it with the URL above, I get a message "Apache - Not
    Found" and a blurb about configuring virtual paths. I I try a route
    through servlet (www.whatever.com/servlet/MyServlet) I get a "requested
    resource is not available" message.
     
    Steve, Jan 23, 2007
    #5
  6. Steve

    Juha Laiho Guest

    Steve <> said:
    >Arne Vajhøj wrote:
    >> Steve wrote:
    >>> Arne Vajhøj wrote:
    >>>> Steve wrote:
    >>>>> I have a servlet that I'd like to access with a url that includes a
    >>>>> subdirectory; e.g., www.whatever.com/mysubdir/MyServlet (because
    >>>>> that subdirectory is a protected area with associated jsp's).


    .... while having the following declarations in web.xml ...

    >>>> <servlet>
    >>>> <servlet-name>XServlet</servlet-name>
    >>>> <servlet-class>com.whatever.XServlet</servlet-class>
    >>>> </servlet>
    >>>> <servlet-mapping>
    >>>> <servlet-name>XServlet</servlet-name>
    >>>> <url-pattern>/mysubdir/XServlet</url-pattern>
    >>>> </servlet-mapping>


    >> What error do you get ?
    >>

    >I I try to access it with the URL above, I get a message "Apache - Not
    >Found" and a blurb about configuring virtual paths. I I try a route
    >through servlet (www.whatever.com/servlet/MyServlet) I get a "requested
    >resource is not available" message.


    .... ok; what do you see in your server error logs?

    Also, note that web.xml is sensitive to the element order. So, for example,
    you cannot interleave several <servlet> and <servlet-mapping> elements.
    Instead, you must have all the <servlet> elements one after another in
    your web.xml, and only after the last <servlet> can you have the first
    <servlet-mapping>. Also, placement of <servlet> and servlet-mapping>
    elements in relation to the other web.xml elements is critical.
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Jan 28, 2007
    #6
  7. Steve

    Steve Guest

    Thanks for the reminder about that -- I did have one out of order.
    But, sad to say, that didn't fix the problem. Upon further research, I
    found that none of my mapings are taking. Nor are my filter definitions,
    for that mater. Possibly related, my datasource doesn't work either.

    Is there a way to ask Tomcat what mappings it currently has?


    Steve

    Juha Laiho wrote:
    > Steve <> said:
    >> Arne Vajhøj wrote:
    >>> Steve wrote:
    >>>> Arne Vajhøj wrote:
    >>>>> Steve wrote:
    >>>>>> I have a servlet that I'd like to access with a url that includes a
    >>>>>> subdirectory; e.g., www.whatever.com/mysubdir/MyServlet (because
    >>>>>> that subdirectory is a protected area with associated jsp's).

    >
    > ... while having the following declarations in web.xml ...
    >
    >>>>> <servlet>
    >>>>> <servlet-name>XServlet</servlet-name>
    >>>>> <servlet-class>com.whatever.XServlet</servlet-class>
    >>>>> </servlet>
    >>>>> <servlet-mapping>
    >>>>> <servlet-name>XServlet</servlet-name>
    >>>>> <url-pattern>/mysubdir/XServlet</url-pattern>
    >>>>> </servlet-mapping>

    >
    >>> What error do you get ?
    >>>

    >> I I try to access it with the URL above, I get a message "Apache - Not
    >> Found" and a blurb about configuring virtual paths. I I try a route
    >> through servlet (www.whatever.com/servlet/MyServlet) I get a "requested
    >> resource is not available" message.

    >
    > ... ok; what do you see in your server error logs?
    >
    > Also, note that web.xml is sensitive to the element order. So, for example,
    > you cannot interleave several <servlet> and <servlet-mapping> elements.
    > Instead, you must have all the <servlet> elements one after another in
    > your web.xml, and only after the last <servlet> can you have the first
    > <servlet-mapping>. Also, placement of <servlet> and servlet-mapping>
    > elements in relation to the other web.xml elements is critical.
     
    Steve, Feb 2, 2007
    #7
    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. Dave Mitchell

    Re: subdirectory settings

    Dave Mitchell, Jul 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    389
    Dave Mitchell
    Jul 15, 2003
  2. Multicoder4002
    Replies:
    2
    Views:
    1,983
    Wendy S
    Feb 5, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    2,045
    Jack Jia
    Apr 4, 2004
  4. Replies:
    4
    Views:
    705
    santax
    Apr 20, 2007
  5. Patino
    Replies:
    0
    Views:
    700
    Patino
    Feb 17, 2007
Loading...

Share This Page