Struts 1 + Spring 3语言和主题支持+ Tiles

时间:2014-01-15 10:09:09

标签: java spring internationalization tiles struts-1

我正在开发一个旧的Struts 1应用程序。我试图从Spring 3 MVC添加主题和国际化(i18n)/本地化(L10n)支持。

这是代码: 的web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- Struts Configuration -->
<servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>
        org.apache.struts.action.ActionServlet
    </servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
        <param-name>debug</param-name>
        <param-value>2</param-value>
    </init-param>
    <init-param>
        <param-name>detail</param-name>
        <param-value>2</param-value>
    </init-param>
    <init-param>
        <param-name>validate</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>autowire</param-name>
        <param-value>byName</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- Struts Configuration -->

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->

<!-- welcome file list -->
<welcome-file-list>
    <welcome-file>welcome.do?method=test</welcome-file>
</welcome-file-list>
<!-- welcome file list -->

<!-- tld configuration -->
<jsp-config>
    <taglib>
        <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
        <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
    </taglib>
</jsp-config>
<!-- tld configuration -->

的struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"/WEB-INF/tiles-config.dtd"><struts-config>
<form-beans>
<form-bean name="myForm" type="forms.myForm" />
</form-beans>

<action-mappings>
<action name="myForm" type="actions.myFormAction"
        path="/welcome" scope="request" parameter="method">
        <forward name="signin" path="welcome" />
    </action></action-mappings>

<controller>
    <set-property property="processorClass"
        value="actions.CustomRequestProcessor" />
</controller>

<plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
    <set-property property="moduleAware" value="true" />
</plug-in>

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation"
        value="/WEB-INF/dispatcher-servlet.xml" />
</plug-in>

调度-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <!--  <property name="basename" value="classpath:messages" /> -->
    <property name="basename" value="/WEB-INF/classes/resources/Applicationresource" />
    <property name="defaultEncoding" value="UTF-8"/>
    <property name="cacheSeconds" value="5"/>
    <property name="UseCodeAsDefaultMessage" value="true"/>
</bean>

<!-- Locale Change Intercepter and Resolver definition -->
<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="en" />
</bean>


<bean id="themeSource"
    class="org.springframework.ui.context.support.ResourceBundleThemeSource">
    <property name="basenamePrefix" value="theme-" />
</bean>

<!-- Theme Change Intercepter and Resolver definition -->
<bean id="themeResolver"
    class="org.springframework.web.servlet.theme.CookieThemeResolver">
    <property name="defaultThemeName" value="default" />
</bean>

<mvc:interceptors>
    <bean id="themeChangeInterceptor"
        class="org.springframework.web.servlet.theme.ThemeChangeInterceptor">
        <property name="paramName" value="theme" />
    </bean>

    <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="language" />
    </bean>

    <bean id="themeAndLanguageInterceptor"
        class="common.interceptor.ThemeAndLanguageInterceptor">
        <property name="paramName" value="LUSSI" />
    </bean>
    <bean id="handlerInterceptorclass" class="common.interceptor.HandlerInterceptor">
        <property name="themParamName" value="theme" />
        <property name="languagParamName" value="language" />
    </bean>

</mvc:interceptors>

瓦片-defs.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN" "/WEB-INF/tiles-config.dtd">
<tiles-definitions>
<definition name="base.definition1" template="/WEB-INF/jsp/layout1.jsp">
<put name="body" value="" />
</definition>
<definition name="welcome" extends="base.definition1">
<put name="title" value="Home" />
<put name="body" value="/home.jsp" />
</definition>
</tiles-definitions>

针对home.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Home</title>
<link rel="stylesheet" type="text/css" href="<spring:theme code='css'/>" />

但是当我运行应用程序时,我收到以下错误:

javax.servlet.jsp.JspTagException: Theme 'theme': No message found under code 'css' for locale 'en_IN'.

有人知道如何解决它吗?提前谢谢。

0 个答案:

没有答案