struts资源包属性文件不映射某些键

时间:2014-01-25 15:30:03

标签: java jsp properties struts

我开始研究struts,我在使用资源属性文件时遇到了问题

页面上的某些文字显示为:

???login.message???
???login.username???    
???login.password???

但是从属性文件中正确获取了一些其他消息。我认为属性文件配置正确,但我遗漏了一些东西,无法正确显示。

文件ApplicationResources.properties

# Resources for Login Project

# Struts Validator Error Messages
# These two resources are used by Struts HTML tag library
# to format messages. In this case we make sure that errors
# are red so that they can be noticed.
errors.header=<font color="red">* 
errors.footer=</font>

#errors associated with the Login page
error.username.required=username required.
error.password.required=password required
error.login.invalid=The system could not verify your username or password. Is your CAPS LOCK on? Please try again.

#login page text
login.title=this is a title
login.message=please log in

login.username=username:
login.password=password:
login.button.signon=Log In

#loggedin page text
loggedin.title=Login Project
loggedin.msg=Benvenuto, {0}. You are now logged in.

“error.login.invalid”正确显示,“error.username.required”也是

登录标签不是

这是我的jsp页面

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<html:html locale="true"/>

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<fmt:bundle basename="ApplicationResources"/>
<title><fmt:message key="login.title"/></title>

</head>
<body>
<html:errors property="login"/>
<html:form action="login.do" focus="userName" >
<table align="center">
        <tr align="center">
            <td><H1><fmt:message key="login.message"/></H1></td>
        </tr>
        <tr align="center">
            <td>
                <table align="center">
                    <tr>
                        <td align="right">
                            <fmt:message key="login.username"/>
                        </td>
                        <td align="left">
                            <html:text  property="userName" 
                                        size="15" 
                                        maxlength="15" />
                            <html:errors property="userName" />
                        </td>
                    </tr>   
                    <tr>
                        <td align="right">
                            <fmt:message key="login.password"/>
                        </td>
                        <td align="left">
                            <html:password  property="password" 
                                            size="15" 
                                            maxlength="15" 
                                            redisplay="false"/>
                            <html:errors property="password" />
                        </td>
                    </tr>   
                    <tr>
                        <td colspan="2" align="center">
                            <html:submit>
                                <fmt:message key="login.button.signon"/>
                            </html:submit>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>


</html:form>





</body>
</html>
你能帮帮我吗? TKZ

1 个答案:

答案 0 :(得分:1)

你的

<fmt:message ... />

标签需要在

<fmt:bundle ... >

标签。目前,您正在关闭bundle标记

<fmt:bundle basename="ApplicationResources"/>

相反,打开它

<fmt:bundle basename="ApplicationResources">

并关闭它

</fmt:bundle>

当您不再需要它时,可能在JSP的末尾。嵌套你的

<fmt:message key="login.title"/>
里面有

标签。