Results 1 to 3 of 3

Thread: Solutions for mapping everything to / ?

  1. #1

    Default Solutions for mapping everything to / ?

    Ok, so let's brainstorm a little. What's the best way to do this?

    One solution is to map it like this:

    Code:
    <servlet-mapping>
    	<servlet-name>squabble</servlet-name>
    	<url-pattern>/</url-pattern>
    </servlet-mapping>
    This almost works; assuming you have your JSPs under WEB-INF/, they will be returned. Any content not under WEB-INF (CSS, JS, images so the client browser can get to it)? Not so much.

    Not a great solution.

    Another way would be to figure out how to tell the DispatcherServlet to ignore any requests that didn't match a handler (Controller or what not) - I haven't yet identified a way to do this.

    Another is to store your static content as either resources in a jar or under WEB-INF/classes or just under WEB-INF, and write a Handler to return those resources. Not the greatest solution either as you're duplicating something your container already does (does anyone have an example of this though?)

    Is there anything I'm missing. I'm a big fan of pretty urls.

  2. #2

    Default

    No ideas? Wicket pulls it off, though I suspect it's the use of a filter instead of a dispatcher servlet...

  3. #3

    Default

    I actually ended up coming up with a pretty decent solution. I use UrlRewriteFilter

    http://tuckey.org/urlrewrite/

    I map my spring server to /view/* like so:

    Code:
    	
    <servlet>
    	<servlet-name>myapp</servlet-name>
    	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    	<load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
    	<servlet-name>myapp</servlet-name>
    	<url-pattern>/view/*</url-pattern>
    </servlet-mapping>
    Then add the filter for UrlRewrite

    Code:
    <filter>
    	<filter-name>UrlRewriteFilter</filter-name>
    	<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    
    </filter>
    <filter-mapping>
    	<filter-name>UrlRewriteFilter</filter-name>
    	<url-pattern>/*</url-pattern>
    </filter-mapping>
    And then set up the urlrewrite rules:
    Code:
    <urlrewrite>
            <!-- don't process certain requests -->
    	<rule>
    		<from>^(.*(.jpg|.gif|.png|.css|.js$|/errorpages/|.ico|/j_spring_security_check).*)$</from>
    		<to last="true">$1</to>
    	</rule>
            
            <!-- Do the rewriting -->
    	<rule match-type="wildcard">
    		<from>/**</from>
    		<to last="false">/view/$1</to>
    	</rule>
    </urlrewrite>
    So if the browser hits /foo, the filter will rewrite to /view/foo.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •