问题描述
||
当我将此tld和自定义标签添加到我的jsp中时,Spring在启动时抛出错误。正在加载的页面\'index.jsp \'被配置为该应用程序的默认首页。请解释为什么会这样?在将标记添加到页面之前,一切都会按预期进行。
头标
<%@ attribute name=\"title\" required=\"true\" description=\"Page\'s title\" %>
<%@ taglib uri=\"http://www.springframework.org/tags\" prefix=\"spring\" %>
<%@ taglib uri=\"../mytags.tld\" prefix=\"pbl\" %>
<head>
<title>
<spring:message code=\"${title}\" text=\"${title}\"></spring:message>
</title>
<script type=\"text/javascript\" src=\"resources/scripts/global.js\"></script>
<script type=\"text/javascript\" src=\"resources/scripts/jquery-1.6.1.min.js\"></script>
<script type=\"text/javascript\" src=\"resources/scripts/jquery-ui-1.8.13.custom.min.js\"></script>
<link rel=\"stylesheet\" type=\"text/css\" href=\"resources/styles/global.css\" media=\"screen\" />
<link rel=\"stylesheet\" type=\"text/css\" href=\"resources/styles/dark-hive/jquery-ui-1.8.13.custom.css\" media=\"screen\" />
<jsp:dobody />
</head>
index.jsp
<%@ taglib uri=\"/WEB-INF/mytags.tld\" prefix=\"pbl\" %>
<html>
<pbl:head title=\"hello\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"resources/styles/global.css\" media=\"screen\" />
</pbl:head>
<body>
<a href=\"home\">Say Hello</a>
</body>
</html>
错误
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 3
1: <%@ taglib uri=\"/WEB-INF/mytags.tld\" prefix=\"pbl\" %>
2: <html>
3: <pbl:head title=\"hello\">
4: <link rel=\"stylesheet\" type=\"text/css\" href=\"resources/styles/global.css\" media=\"screen\" />
5: </pbl:head>
6: <body>
root cause
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.context.support.WebApplicationContextUtils.getrequiredWebApplicationContext(WebApplicationContextUtils.java:84)
org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:81)
org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:219)
org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:74)
org.springframework.web.servlet.support.JspAwareRequestContext.<init>(JspAwareRequestContext.java:48)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:76)
org.apache.jsp.tag.web.head_tag._jspx_meth_spring_005fmessage_005f0(head_tag.java:132)
org.apache.jsp.tag.web.head_tag.doTag(head_tag.java:85)
org.apache.jsp.index_jsp._jspx_meth_pbl_005fhead_005f0(index_jsp.java:93)
org.apache.jsp.index_jsp._jspService(index_jsp.java:63)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
解决方法
因为弹簧标签需要弹簧应用。为此,您需要在web.xml中将
ContextLoaderListener
定义为ѭ4suspect(我怀疑映射DispatcherServlet
也应该没问题,尽管消息未指出)