0

I have foo.war running in Tomcat via Eclipse. I am using Spring Mvc. When I attempt to view the index page for this context:

http://localhost:8080/foo

I get: HTTP Status 404 - /foo/WEB-INF/pages/index.jsp

My Maven project has a src/main/webapp/WEB-INF/jsp/pages/index.jsp.

For some reason, this has to be in the .war maven module; it cannot be in a separate jar module included in the war as a dependency in maven. Which is strange, as Tomcat is picking up my servlet config in this separate maven module.

The view in Spring Mvc is configured in the following way:

InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/pages/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);

My controller is like this:

@RequestMapping("/")
public String index(Map<String, Object> model) throws Exception {
    return "index";
}

The servlet mapping is currently "/".

How can I put the jsp in a separate module?

EDIT: Rewritten because a separate problem confused matters

EDIT: Changed some more. Looks like Maven multi-module build is involved...

drrob
  • 632
  • 7
  • 16
  • In the case of the resources (Spring Mvc asset pipeline) in my original question, this was a red herring, so I think it is only an issue for resolving the internal view – drrob Dec 13 '15 at 13:15
  • 1
    I'm not sure what your question is. The prefix in InternalResourceViewResolver and the url in RequestMapping **is already** relative to the application context path. What are you trying to achieve, and what is the problem you're facing? If your goal is to forward to a view that is not part of your webapp, that can't happen. Each webapp is independant. – JB Nizet Dec 13 '15 at 13:21
  • I've pretty much rewritten my question, it should be clearer now – drrob Dec 13 '15 at 13:30
  • 1
    Does your controller get injected? It seems that your controller doesn't invoke the method `index`. How does your servlet-mapping look like? – Julian L. Dec 13 '15 at 13:41
  • Aha! The .jsp was in a separate maven module, but if I put it in the .war module then it is picked up. So something isn't liking jsp being in a separate jar (even though that's where all the controllers and servlet config is!)... So, how can I put the jsp in a separate module? – drrob Dec 13 '15 at 13:44
  • 2
    http://stackoverflow.com/questions/5013917/can-i-serve-jsps-from-inside-a-jar-in-lib-or-is-there-a-workaround – JB Nizet Dec 13 '15 at 15:20
  • Thanks JB Nizet, I added that to my answer – drrob Dec 14 '15 at 13:24

1 Answers1

0

OK,

So it was putting the jsp in a separate jar that did it.

I should have used:

META-INF/resources

not

WEB-INF

See also: Can I serve JSPs from inside a JAR in lib, or is there a workaround?

Note that it is probably easier just to not use jsp, which must go back to the servlet container from Spring. Instead Velocity/Freemarker/Thymeleaf templates can be managed entirely with Spring. It is also convenient to put the templates in src/main/resources, rather than in these ugly META-INF/WEB-INF folders.

Community
  • 1
  • 1
drrob
  • 632
  • 7
  • 16