扩展JSTL View类

时间:2012-08-08 09:08:03

标签: spring spring-mvc

我正在扩展JSTL视图类以实现我自己的视图解析器。但是,我遇到了问题。看看我的代码:

public class TestView extends JstlView {
    private String fo_suffix = "_jo";

    public void setUrl(String url)
    {
        //We need to change the inputed url to add a prefix for fo
        super.setUrl(url.replace("\\.jsp", fo_suffix+ ".jsp"));
    }
    public void render(Map<String, ?> model, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        final StringWriter xmlfo = new StringWriter();

        HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper(
                response) {
            @Override
            public PrintWriter getWriter() throws IOException {
                return new PrintWriter(xmlfo);
            }
        };



        super.render(model, request, wrapper);

在上面的代码中,当我调试时,控件永远不会出现在 setUrl 方法中。因此,内部RequestDispatcher中的url始终为null。

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

别忘了将TestView放在“myServletName”-servlet.xml

<bean id="viewResolver"    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="test.TestView"/>
....