0

通常这就是我创建 JSP 文件的方式

<html>
 <head>
  <%@ include file="initDirectives.jsp"%>
  <%@ include file="header-site.jsp"%>
  <title><spring:message code="menu.about.us" /></title>
 </head>
 <body>
      aboutttttttt.
 </body>
</html>

我希望能够在我的页面上删除我的 JSP 文件的 2 包含,它们是:

  1. initDirectives.jsp其中包含类似的<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>代码
  2. header-site.jsp其中包含我页面上菜单链接的标题

配置我的 Sitemesh 配置后,我创建default.jsp如下

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="decorator"
    uri="http://www.opensymphony.com/sitemesh/decorator"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="../views/initDirectives.jsp"%>
<%@ include file="../views/header-site.jsp"%>
<title><decorator:title default="DNA G2" /></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<decorator:head />
</head>
<body>
    <div class="container clear-top">
        <decorator:body />
        <br>
        <div id="footer">
            <div class="container">
                <p class="muted credit">© 2013 DNA G2. All Rights Reserved.</p>
            </div>
        </div>
    </div>
</body>
</html>

最后,这是我的 JSP 页面包含的内容

<head>
<title><spring:message code="menu.about.us" /></title>
</head>
<body>aboutttttttt.
</body>

问题是spring:message标签不再被识别。我在这里错过了什么?

4

2 回答 2

0

<html>尝试在您的 default.jsp 中移动 taglib 包含语句。

于 2013-09-20T06:39:47.360 回答
0

要使用 spring:message,您的项目必须在 applicationContext.xml 中包含以下 bean:

<bean id="messageSource"  
        class="org.springframework.context.support.ResourceBundleMessageSource">  
    <property name="basename" value="messages"/>  
  </bean> 

(您的消息现在将存储在一个名为:messages_en.properties(用于英语)、messages_lt.properties(用于立陶宛语)等文件中。)

然后确保您的 JSP 页面包含 Spring 的 taglib(示例来自我的项目):

<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>**


<html>
<head>
.....

将 spring-core JAR 添加到您的项目中。

或者你也可以看看这个教程:http ://www.mkyong.com/spring-mvc/spring-mvc-internationalization-example/

希望这可以帮助 :)

于 2013-09-20T05:49:02.767 回答