Mapping Spring framework 3 resources

In fact, I ran into the following problem:

I am using Spring with jQuery. I have a controller:

@Controller @RequestMapping(value = "/A") public class AController { // not important } 

This handles all host/A/... URLs in order. But jQuery CSS styles use url(images/...) , so there are links from host/A/index.jsp to host/A/images/... But I do not have such a folder, since / A / is just a "logical" URL.

I tried to add

 <mvc:resources mapping="/images/**" location="/images/" /> <mvc:resources mapping="/A/images/**" location="/images/" /> 

in my web.xml, but it seems like it is not working (the first one works fine). For example, when I try to verify this, host/A/test.png does not work.

Of course, I can modify jQuery sources, but I am not exaggerating this.

Maybe I can use UrlRewriteFilter if there is no simpler solution.

0
java spring
source share
2 answers

I suggest you use the BASE tag in the resulting HTML:

 <html> <head> <base href="http://localhost:8080/myApp/" /> .... 

Then the entire image request will be executed using http://localhost:8080/myApp/images/... if you are at http://localhost:8080/myApp/ or at http://localhost:8080/myApp/A/

+1
source share

If you are on an application server such as tomcat, you can do this in the web.xml file:

  <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/images/*</url-pattern> </servlet-mapping> 

In my projects I usually put something like this;)

  <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.PNG</url-pattern> <url-pattern>*.png</url-pattern> <url-pattern>*.gif</url-pattern> <url-pattern>*.js</url-pattern> <url-pattern>*.css</url-pattern> <url-pattern>*.jpg</url-pattern> <url-pattern>*.swf</url-pattern> <url-pattern>*.avi</url-pattern> <url-pattern>*.html</url-pattern> <url-pattern>*.json</url-pattern> </servlet-mapping> 

In doing so, you need to create a physical folder. / A / images /.

In another application server, the value may change.

0
source share

All Articles