没有评估Spring jsp页面
我对Spring 3.1.0有一个有趣的问题。 JSP页面没有评估EL。 我调试了视图解析过程,正在使用JstlView并检测到Jstl库。 但是,我的JSP页面只是渲染类似的东西
这里有很多关于这个问题的参考资料,其中没有一个对我有用。
脚本标记未在JSP页面中呈现(使用Spring + Tiles + JSPX) Spring和JSP EL未被处理
从顶部开始,这是我的配置;
web.xml中
spring org.springframework.web.servlet.DispatcherServlet 1 spring /* contextConfigLocation classpath:applicationContext.xml org.springframework.web.context.ContextLoaderListener org.springframework.web.context.request.RequestContextListener
为spring-servlet.xml
applicationContext.xml中
UTF-8 UTF-8 macros.ftl spring.ftl as spring ${freemarker.template.update.delay} ${google.analytics.id}
我正在使用ContentNegotiatingViewResolver,因为我也有一些freemarker的东西和REST。
调节器
@RequestMapping("/") @Controller public class RootResource extends AbstractResource { ...abridged... @RequestMapping(value="/jsp", method = RequestMethod.GET, produces = "text/html") public String getJSP(final Model m) { return "example"; } }
example.jsp
Hello World JSP Page.
我从控制器返回“example”作为视图名称,你可以在日志中看到它解析为正确的WEB-INF / jsp / example.jsp
22:35:13,049 DEBUG [1168657208@qtp-1342126426-0] [org.springframework.web.servlet.view.ContentNegotiatingViewResolver] Returning [org.springframework.web.servlet.view.JstlView: name 'example'; URL [/WEB-INF/jsp/example.jsp]] based on requested media type 'text/html' 22:35:13,050 TRACE [1168657208@qtp-1342126426-0] [org.springframework.web.servlet.view.JstlView] Rendering view with name 'example' with model {} and static attributes {} 22:35:13,054 DEBUG [1168657208@qtp-1342126426-0] [org.springframework.web.servlet.view.JstlView] Forwarding to resource [/WEB-INF/jsp/example.jsp] in InternalResourceView 'example'
所以一切看起来都不错,只是JSP页面永远不会被正确评估。
example.jsp看起来像这样
我正在使用Maven jetty 6插件来运行webapp。
我敢肯定我错过了一些简单的东西,这可能是其中一个“看了太长时间”的问题。
感谢您提供的任何指示。
更新1 – 我刚刚将Spring servlet映射从/*
更改为/spring/*
,现在它可以工作了。 所以有一些关于Spring servlet被映射到/*
细节我已经错过了。
绝对是一个“长时间看待它”的案例。
spring servlet需要是默认的servlet。 ie映射到/
而不是/*
。
spring org.springframework.web.servlet.DispatcherServlet 1 spring /