1

I have a mapped url to /foo.jsp wich redirects to a controller, but it is not handled by spring and returns a 404. It seems that the url is ignored and directly send to tomcat. Is it possible to make spring handle it ?

To reproduce, starting from https://github.com/spring-projects/spring-boot/tree/1.4.x/spring-boot-samples/spring-boot-sample-tomcat7-jsp just add :

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/foo", "/").setStatusCode(HttpStatus.MOVED_PERMANENTLY);
        registry.addRedirectViewController("/foo.html", "/").setStatusCode(HttpStatus.MOVED_PERMANENTLY);
        registry.addRedirectViewController("/foo.jsp", "/").setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    }
}

Then navigating to /foo and /foo.html works as expected, but /foo.jsp returns a 404

Gabriel Bleu
  • 9,703
  • 2
  • 30
  • 43
  • 1
    Using [UrlRewriteFilter](http://tuckey.org/urlrewrite/) I was able to redirect a jsp url, but the spring behavior feels buggy. – Gabriel Bleu Sep 29 '16 at 10:27

1 Answers1

1

Would you use a viewResolver to handle the jsp views. And segregate html and jsp views differently using this technique.

Community
  • 1
  • 1
Akash Mishra
  • 682
  • 1
  • 5
  • 13
  • We are in the process of migrating jsp/scriptlets to mvc, the whole point is to keep referenced url up by redirecting to the new one – Gabriel Bleu Sep 27 '16 at 14:47