flybywire
flybywire

Reputation: 273452

spring mvc 3.0: put a bunch of .jsp files under spring's control

In my spring mvc 3.0 project I have a directory full of .jsp files (~150) which I want to put under spring's control.

Until now they where invoked by web.xml directly, without going thru the spring servlet.

From now, I want to put them all under spring's control to enjoy spring's goodies and make my project more uniform.

Of course, I don't want to write a single controller for each .jsp file. How can I do this?

Upvotes: 1

Views: 632

Answers (2)

axtavt
axtavt

Reputation: 242686

In the case of a single JSP page you can use <mvc:view-controller>.

When you have many pages, you can write a catch-all controller like this:

@RequestMapping("/folder/{name}.jsp")
public ModelAndView catchAll(@PathVariable String viewName) {
    return new ModelAndView("legacy/" + viewName);
}

However, it may conflict with JSP processing servlet. If so, you need to apply some URL rewriting filter.

Upvotes: 1

Bozho
Bozho

Reputation: 597016

JSPs must not include any code that requires dependency injection. So don't do it.

If you really must, you can use

<%!
    public void init() {
        ApplicationContextUtils.getRequiredWebApplicationContext(
             getServletContext()).getAutowireCapableBeanFactory()
             .autowireBean(this);
    }
%>

But this is extremely ugly.

Upvotes: 0

Related Questions