简体   繁体   English

struts资源束属性文件未映射某些键

[英]struts resource bundle properties file not mapping some keys

I'm starting to study struts and I have a problem using resource properties file 我开始研究struts,使用资源属性文件时遇到问题

some text on page is displayed as this: 页面上的一些文本显示如下:

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

but some other messages are correctly taken from properties file. 但是某些其他消息是从属性文件中正确提取的。 I think that the propertis file is correctly configured but I'm missing something to display anything correctly. 我认为正确配置了属性文件,但是我缺少一些东西来正确显示任何东西。

the file ApplicationResources.properties 文件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" is correctly displayed and "error.username.required" too 正确显示“ error.login.invalid”,也显示“ error.username.required”

the login label not 登录标签不是

this is my jsp page 这是我的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>

Can you help me ? 你能帮助我吗 ? tkz TKZ

Your 你的

<fmt:message ... />

tags need to be inside an 标签必须位于

<fmt:bundle ... >

tag. 标签。 Currently you are closing your bundle tag right away 目前,您即将关闭bundle代码

<fmt:bundle basename="ApplicationResources"/>

Instead, open it 而是打开它

<fmt:bundle basename="ApplicationResources">

and close it 并关闭它

</fmt:bundle>

when you no longer need it, possibly at the end of your JSP. 当您不再需要它时,可能在JSP的结尾。 Nest your 嵌套你的

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

tags inside it. 里面的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM