Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Spring
Problem in I18N in Spring
vivek dhiman
Ranch Hand
Posts: 157
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I have below code & trying to run in eclipse. It giving message resource not available. This might be an issue of mapping. Below is my code, please check.
Controller
package com; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; public class ExampleController extends AbstractController{ @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView model = new ModelAndView("localeExample"); return model; } }
properties file
welcome = Bienvenue à l'exemple Locale welcome = Welcome to Locale Example
View is :
<%@ page contentType="text/html;charset=UTF-8" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <html> <body> <a href="?ln=en">Click to set English Language</a><br/> <a href="?ln=fr_FR">Click to set French Language</a> <h1><spring:message code="welcome"/></h1> </body> </html>
Dispatcher
Servlet
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean name="/localeExample.jsp" class="com.ExampleController" /> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="message" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name="prefix"> <value>/WEB-INF/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>SpringI18N</display-name> <servlet> <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>*.jsp</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/localeExample.jsp</welcome-file> </welcome-file-list> </web-app>
Directory-Structure.png
Ashwini Kashyap
Ranch Hand
Posts: 90
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You need to register beans to make support internationalization something like:
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" >
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
Thanks,
Ashwini Kashyap | www.infocepts.com
vivek dhiman
Ranch Hand
Posts: 157
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
Thanks for reply. I changed the web.xml but getting the same error when run the application.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> <property name="defaultLocale" value="en" /> </bean> <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> <property name="paramName" value="ln" /> </bean> <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" > <property name="interceptors"> <list> <ref bean="localeChangeInterceptor" /> </list> </property> </bean> <bean name="/localeExample.jsp" class="com.ExampleController" /> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="message" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name="prefix"> <value>/WEB-INF/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
Below Error I am getting on console.
Dec 18, 2012 3:02:56 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI [/SpringI18N/] in DispatcherServlet with name 'dispatcher'
Ashwini Kashyap
Ranch Hand
Posts: 90
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I think problem is that its unable to find the controller class. Try like:
<context:component-scan base-package="*.*"/> // Write your class package here
vivek dhiman
Ranch Hand
Posts: 157
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Changes made, but still not work.
dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com"/> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> <property name="defaultLocale" value="en" /> </bean> <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> <property name="paramName" value="ln" /> </bean> <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" > <property name="interceptors"> <list> <ref bean="localeChangeInterceptor" /> </list> </property> </bean> <bean name="/localeExample.jsp" class="com.ExampleController" /> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="message" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name="prefix"> <value>/WEB-INF/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Spring WEB MVC 3.0 using org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport
Disable HTML frame using Javascript
hibernate 4 and spring 3.1.2 issue with LocalSessionFactoryBuilder
Simple JPA application on TOMEE
Error in First Hibernate Example
More...