java - Where to put text properties? -


i'm trying localization java web application , getting error. using maven dependencies , using google app engine (jetty web server). application using spring framework. here have far:

project structure:

enter image description here

messages_en_us.properties

label.firstname=first name label.lastname=last name 

index.jsp

<%@page contenttype="text/html" pageencoding="utf-8"%> <%@taglib prefix="t" tagdir="/web-inf/tags"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <t:genericpage>     <jsp:attribute name="title">       welcome     </jsp:attribute>     <jsp:body>         <script type="text/javascript" src="../static/js/index.js"></script>         <div class="flex_container_column">             <spring:message code="label.firstname" />             <br>             <spring:message code="label.lastname" />             <br>         </div>     </jsp:body> </t:genericpage> 

spring-mvc-servlet.xml

<mvc:resources mapping="/static/**" location="/static/" /> <mvc:annotation-driven /> <bean id="viewresolver"     class="org.springframework.web.servlet.view.urlbasedviewresolver">     <property name="viewclass"         value="org.springframework.web.servlet.view.jstlview" />     <property name="prefix" value="/web-inf/jsp/" />     <property name="suffix" value=".jsp" /> </bean>  <!-- resource bundle message: start --> <bean id="messagesource"     class="org.springframework.context.support.reloadableresourcebundlemessagesource">     <property name="basename" value="messages" />     <property name="defaultencoding" value="utf-8" /> </bean>  <bean id="localechangeinterceptor"     class="org.springframework.web.servlet.i18n.localechangeinterceptor">     <property name="paramname" value="lang" /> </bean>  <bean id="localeresolver"     class="org.springframework.web.servlet.i18n.cookielocaleresolver">     <property name="defaultlocale" value="en" /> </bean>  <bean id="handlermapping"     class="org.springframework.web.servlet.mvc.annotation.defaultannotationhandlermapping">     <property name="interceptors">         <ref bean="localechangeinterceptor" />     </property> </bean> <!-- resource bundle message: end --> 

error

warning: nested in javax.servlet.servletexception: javax.servlet.jsp.jspexception: javax.servlet.jsp.jsptagexception: no message found under code 'label.firstname' locale 'en_us'.: javax.servlet.jsp.jsptagexception: no message found under code 'label.firstname' locale 'en_us'.     @ org.springframework.web.servlet.tags.messagetag.doendtag(messagetag.java:200)     @ org.apache.jsp.index_jsp._jspx_meth_spring_005fmessage_005f0(index_jsp.java:110)     @ org.apache.jsp.index_jsp.access$0(index_jsp.java:97)     @ org.apache.jsp.index_jsp$helper.invoke1(index_jsp.java:176)     @ org.apache.jsp.index_jsp$helper.invoke(index_jsp.java:205) 

pom.xml

<build>     <sourcedirectory>src</sourcedirectory>     <plugins>         <plugin>             <artifactid>maven-compiler-plugin</artifactid>             <version>3.3</version>             <configuration>                 <source>1.7</source>                 <target>1.7</target>             </configuration>         </plugin>         <plugin>             <artifactid>maven-war-plugin</artifactid>             <version>2.6</version>             <configuration>                 <warsourcedirectory>webcontent</warsourcedirectory>                 <failonmissingwebxml>false</failonmissingwebxml>             </configuration>         </plugin>     </plugins> </build> 

i tried few things:

  1. moved messages /web-inf got same error when changed <property name="basename" value="/web-inf/messages" />. per understanding, if so, might not able access in code. why put resources initially.
  2. i removed en_us default messages property file name, got same error.

appreciate on , how setup project property files + text.properties.

i ended putting messages.properties in /webcontent/web-inf/messages/messages.properties , reason getting error because have 2 contexts defined:

  1. applicationcontext.xml
  2. spring-mvc-servlet.xml

i putting configuration in spring-mvc-servlet.xml, not right place. instead, should have been in applicationcontext.xml (the parent context). solved issue faced problem, localechangeinterceptor not intercepting, language can't changed! however, problem resolved.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo