开发者

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

开发者 https://www.devze.com 2023-01-27 11:13 出处:网络
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.

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消