I have a properties file in /WEB-INF/properties/Messages.properties
having content as follow
label.username=Enter User Name
label.password=Enter Password
....
....
I have configure my dispatcher-servlet.xml as follow
dispatcher-servlet.xml:
<context:component-scan base-package="com.st.spring.mvc" />
<mvc:annotation-driven />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames" value="WEB-INF/properties/Messages"/>
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
web.xml:
<welcome-file-list>
<welcome-file>/WEB-INF/jsp/hello.jsp</welcome-file>
</welcome-file-list>
<servlet><br>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
At last , I am trying to read that properties file value in my jsp page as follow
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:message code="label.username"/>
<spring:message code="label.password"/>
Then , I am getting exception like
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/hello.jsp
at line 2
1: <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
2: <spring:message code="label.username"/>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)<br>
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465)<br>
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)<br>
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)<br>
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)<br>
root cause <br>
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?<br>
org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90)<br>
org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:85)<br>
org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:207)<br>
org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:74)<br>
org.springframework.web.servlet.support.JspAwareRequestContext.<init>(JspAwareRequestContext.java:48)<br>
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:76)<br>
org.apache.jsp.WEB_002dINF.jsp.hello_jsp._jspx_meth_spring_005fmessage_005f0(hello_jsp.java:95)<br>
org.apache.jsp.WEB_002dINF.jsp.hello_jsp._jspService(hello_jsp.java:68)<br>
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)<br>
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)<br>
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)<br>
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)<br>
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)<br>
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)<br>
Can anybody solve this problem ?
Put the dispatcher-servlet.xml
information in web.xml
file.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>