java - struts 资源包属性文件未映射某些键

标签 java jsp properties struts

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

页面上的一些文字显示如下:

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

但其他一些消息是从属性文件中正确获取的。我认为 propertis 文件已正确配置,但我缺少正确显示任何内容的内容。

文件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>

你能帮帮我吗? 呵呵

最佳答案

你的

<fmt:message ... />

标签需要在

<fmt:bundle ... >

标签。目前你正在关闭你的 bundle 标签

<fmt:bundle basename="ApplicationResources"/>

相反,打开它

<fmt:bundle basename="ApplicationResources">

并关闭它

</fmt:bundle>

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

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

里面有标签。

关于java - struts 资源包属性文件未映射某些键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21352462/

相关文章:

java - 用于 Spring Boot 获取请求的 mongo uri

java - 使用 Spring MVC 和 Spring Security 在 Multi-Tenancy Web 应用程序中使用表单登录

google-app-engine - 平台中立的 JSP Zip 文件上传 (Google App Engine/Tomcat)

java - 从 JSP 检索嵌套列表的值并将其发送回表单

html - 在 JSP 应用程序中基于 CSS 实现参数化外观的最佳方式是什么?

java - 如何在 java 代码中使用 weka 中的日期类型?

javascript - Java - Rest 端点返回图像(如果可用)和 JSON(如果不可用)

javascript - 使用递归读取对象的属性和属性?

java - Spring Boot - 不覆盖服务器端口属性

ios - 频繁使用计算属性访问对象是否会影响性能?