On Oct 17, 2011, at 6:00 PM, Christopher Schultz wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Nathan,

On 10/17/2011 4:50 PM, Nathan Potter wrote:
Historically, the servlet that I am working with has been the
default servlet. Tomcat's default servlet was used to serve docs
from a subdirectory of the context dir, and everything else was
dynamically generated by the default servlet. JSP was never used so
no there was no issue there.

I'm guessing that "the default servlet" really has at least two
meanings above.. it's not at all clear what you're talking about.

Oh sorry, by default servlet I mean the servlet mapped to "/" or "/*" in the web application. I've been trying to say the "tomcat default servlet" if I mean org.apache.catalina.servlets.DefaultServlet. I'll try to more more explicit.

A new feature has been added to the web application that requires
JSP. But because an alternative default servlet is defined, this
disables the use of the JspServlet using the *.jsp url-pattern in
the servlet mapping. (This may be caused by a failure to properly
implement the alternate default servlet?? I don't know how to
tell.)

Wait, what? Changing the default servlet un-maps the JSP servlet?
Something must be wrong with your configuration.




What I thought to do was:

<servlet-mapping> <servlet-name>hyrax</servlet-name>
<url-pattern>/*</url-pattern> <url-pattern>/hyrax/*</url-pattern>
</servlet-mapping>

FYI those two mappings are redundant: /* includes /hyrax/*. A "*"
doesn't mean "anything but a /", it indicates that anything that
starts with "/hyrax/" should be mapped to the "hyrax" servlet. URL
mappings in web.xml aren't as expressive as just about anyone would
like them to be. Specifically, they are neither simple globs nor are
they regular expressions.

You would think that they would be redundant but in fact the server behaves differently if you use them both.
Having both means that you the same page here:

    context/

and here:

    context/hyrax/

Which has been the expected behavior.





<servlet-mapping> <servlet-name>jsp</servlet-name>
<url-pattern>/jsp/*</url-pattern>
<url-pattern>/admin/*</url-pattern>
<url-pattern>/error/*</url-pattern> </servlet-mapping>

What's wrong with the default, which is "/*.jsp" for the JSP servlet?
Do you have files with the .jsp extension that you need served without
actually invoking the JSP servlet?

No, but if you assign a servlet to "/" or "/*" it gets call foreverything before anything starting with "*". Basically starts with "/" trumps starts with "*" when applying url patterns.


Which worked, but when accessing the URL:

http://localhost:8080/myContext/admin

I would get back a 500 error.

So don't do that :)

:)


And:

http://localhost:8080/myContext/admin/

Would return the (index.jsp) welcome page.

I would have expected an error, same as above.

index.jsp is in the welcome-file-list and apparently the JspServlet is good with that.



Now, one might argue that the first URL should 404, or one might
argue that it should redirect to the 2nd URL. But I think it's a
tough argument to make that it should return a 500 error.

If you implemented your default servlet in the same way that Tomcat's
is done, then a redirect from /admin -> /admin/ will occur.

It is sort of like tomcat but different.

But this is the point. Look at the stack trace. The error is coming from the Jasper JspServlet - my code is not being called. The JspServlet is getting tapped to respond to the request URL http://localhost:8080/contextName/admin


It looks
like you haven't done that. But, if you haven't, then why does the JSP
servlet get invoked? You mapped it to "/admin/*", not to "/admin"...

That's the question isn't it....


And I didn't see anywhere in the documentation that said you
SHOULDN'T use the JSP Servlet this way...

I wrote a work around by subclassing
org.apache.jasper.servlet.JspServlet and wrapping/overriding the
service() method with a check for the directory w/o the trailing
slash condition and returning a redirect when it happens and
passing the call down to super.service() when it doesn't. That
works great, but I figured the 500 error wasn't a desired behavior
so I wrote in to the list about it, as the documentation at Tomcat
home indicated that all bug reports should begin here.

Let's see the change you made. It might not work under all circumstances.

Oh I'm sure it won't. It's a work around, not a patch by any means. Here's the important part:

public class JspServlet extends org.apache.jasper.servlet.JspServlet {

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        String jspUri  = request.getServletPath();

        String pathInfo = request.getPathInfo();
        if (pathInfo != null) {
            jspUri += pathInfo;
        }
        String realPath =   context.getRealPath(jspUri);


        File f = new File(realPath);

        if(f.exists()  &&  f.isDirectory()) {
            String contextPath = context.getContextPath();
StringBuilder redirectUrl = new StringBuilder().append(contextPath).append(jspUri).append("/");

            response.sendRedirect(redirectUrl.toString());

            //super.service(request, response);
            //response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
        else
            super.service(request, response);

    }

)



Thanks for your helpful response.



Nathan



- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk6cz5AACgkQ9CaO5/Lv0PAs0ACfUhNocwUmqavtJ8ilBn5QZPBT
kscAnjRDeapkGccOE4MvsWVqoteuN7wK
=IgYU
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


= = =
Nathan Potter                        ndp at opendap.org
OPeNDAP, Inc.                        +1.541.231.3317





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to