When I add this tld and custom tag to my jsp Spring throws an error on startup. The page ‘index.jsp’ that is loading is configured as the default first page for the application. Please explain why this is happening? Everything works as expected before the tag is added to the page.
head.tag
<%@ 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>
error
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)
Because spring tags expect a spring application. To have such, you need to define a
ContextLoaderListeneras<listener>..</listener>in web.xml (I suspect thta mapping aDispatcherServletshould also be fine, although not indicated by the message)