Spring-mvc - 使用消息时出错500

时间:2017-02-15 10:08:44

标签: jsp spring-mvc spring-messaging

我是Spring-mvc的初学者,我对理解框架非常不满意。我正在关注tuto,但我遇到了一个问题。

(我的项目文件粘贴在下面)

我有src/main/resources/messages_fr.properties包含titre.bonjour,我在jsp中调用它,但是当我部署我的Web应用程序时,我收到错误500:javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'titre.bonjour' for locale 'en_US'.

所以我尝试将messages_fr.properties重命名为messages.properties,同时也在messages_en.properties以及messages_en_US.properties,我甚至尝试将其复制粘贴4次以获取所有内容这些文件...但它永远不会改变......: - /

以下是我的项目文件:有人知道我忘记了什么吗?

├── pom.xml
└── src
    └── main
        ├── resources
        │   ├── messages_en.properties
        │   ├── messages_en_US.properties
        │   ├── messages_fr.properties
        │   └── messages.properties
        └── webapp
            ├── vues
            │   └── bonjour.jsp
            └── WEB-INF
                ├── dispatcher-servlet.xml
                └── web.xml

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>mathis</groupId>
    <artifactId>minimif</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>minimif Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>minimif</finalName>
    </build>
</project>

所有src / main / ressources / messages * .properties:

titre.bonjour=Wesh avec Spring
libelle.bonjour.lemonde=Wesh les gros avec Spring

src / main / webapp / bues / bonjour.jsp:

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<!DOCTYPE html PUBLIC "-//W3CDTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title><spring:message code="titre.bonjour"/></title>
    </head>
    <body>
        <spring:message code="libelle.bonjour.lemonde"/>
    </body>
</html>

src / main / webapp / WEB-INF / 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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context-4.0.xsd
                           http://www.springframework.org/schema/mvc
                           http://www.springframework.org/schema/mvc/spring-mvc.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="ISO-8859-1" />
    </bean>
</beans>

src / main / webapp / WEB-INF / web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <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>
</web-app>

非常感谢! ( - :

0 个答案:

没有答案