David/Hassan,

I've written a filter since I couldn't get the <servlet-mapping> approach to work.

This is what I've got.  It needs generalization, but it does the job.

My question is this: what is the right way to forward the request? The way I'm doing it bypasses the rest of the filter chain...or does the filter chain get reinvoked when the dispatcher forwards the request?

    public void doFilter(
        final ServletRequest request,
        final ServletResponse response,
        final FilterChain chain)
        throws IOException, ServletException
    {
final HttpServletRequest httpRequest = (HttpServletRequest)request;

// very specific handling: forward /diglloyd/blog.html to /diglloyd/ blog.jsp
        // should be generalized and/or do so based on init parameters
        final String queryString = httpRequest.getQueryString();
        if ( queryString == null )
        {
            final String uri = httpRequest.getRequestURI();
            if ( uri.equals( "/diglloyd/blog.html") )
            {
final RequestDispatcher disp = request.getRequestDispatcher("/diglloyd/blog.jsp");
                disp.forward(request, response);
            }
        }
        else
        {
            chain.doFilter(request, response);
        }
    }


    <filter>
<description>maps /diglloyd/blog.html to /diglloyd/blog.jsp</ description>
        <filter-name>BlogFilter</filter-name>
        <filter-class>com.diglloyd.tomcat.BlogFilter</filter-class>
        </filter>
    <filter-mapping>
        <filter-name>BlogFilter</filter-name>
        <url-pattern>/diglloyd/blog.html</url-pattern>
    </filter-mapping>



On Mar 24, 2008, at 8:12 AM, David Smith wrote:
Oh and by the way ... Hassan's idea is really good as well. For that, you just need to write a class that implements the javax.servlet.Filter interface and define the servlet in your web.xml file.
The servlet spec is an excellent resource for this kind of stuff:

http://jcp.org/aboutJava/communityprocess/final/jsr154/index.html

It has docs for the classes/interfaces in javax.servlet as well as docs on what's valid in the web.xml file.

--David

DIGLLOYD INC wrote:

David,

I'm new to programming Servlets/JSP, I didn't realize a <servlet- mapping> could just specify a <url-pattern> an not specify a servlet class, nor do I understand exactly what this example mapping does (and if it does it without other side-effects).

Do you mean to use this in conjunction with a "blog.jsp" which would then include blog.html?

Lloyd

On Mar 24, 2008, at 5:13 AM, David Smith wrote:

Here's a possibility:

Write the quick and dirty blog jsp, name it blog.html, and then add this to your web.xml file:

<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>blog.html</url-pattern>
</servlet-mapping>

The idea is to specifically map blog.html to the jsp servlet for jsp processing. I haven't tried it, but it seems like it should work.

--David

DIGLLOYD INC wrote:

I'm converting from an Apache http system.

Thousands of my users have bookmarked http://diglloyd.com/diglloyd/blog.html

With Apache, I symlinked blog.html to the current month's blog.

Now with Tomcat, I see warnings that enabling symlinks is a security
risk.

What is the best way to make blog.html => 2008-03-blog.html ? (eg if
March 2008 is the current blog)

I realize that I can write a one-line blog.jsp which includes the
current month's blog.  But that won't help users that bookmarked
blog.html.

An http redirect works, but it seems the google search engine is not
enamored of redirects; I don't want to hurt my search ranking.

Lloyd Chambers




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Lloyd Chambers
http://diglloyd.com

[Mac OS X 10.5.2 Intel, Tomcat 6.0.16]





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to