我遇到了与旧Java Web应用程序的internazionalization \ localization相关的以下问题。
所以我有这种情况:我有两个非常相似的Web应用程序,我不得不从第一个获取JSP页面并将其复制到第二个。
此JSP页面包含以下内容:
<thead>
<tr>
<th><input id="myCheck" onclick="changeBoxAll(this)" type="checkbox"></th>
<th></th>
<th><fmt:message key="emittente_fatt"/></th>
<th><fmt:message key="mandataria"/></th>
<th><fmt:message key="id"/></th>
<th><fmt:message key="numero_fatt"/></th>
<th><fmt:message key="data_invio"/></th>
<th><fmt:message key="data_approvazione"/></th>
<th><fmt:message key="data_documento"/></th>
<th><fmt:message key="totale_fattura"/></th>
<th><fmt:message key="stato"/></th>
</tr>
</thead>
正如您在上面的代码中看到的,它包含 标记。
此标记属于JSTL标记库,用于将键映射到本地化消息并执行参数替换。
因此,例如,第一个应用程序中的 显示为发票发行者(如果用户是engligh)或 emittente_fatt = Emittente fattura (如果用户是意大利人)。
在第一个应用程序(从我将JSP推入第二个应用程序的orignal)中,它工作正常,这些日期存储在2个属性文件中,这些文件各自名称:
(第一个用于英文版,第二个用于意大利版)。
因此,在第二个Web应用程序中,我没有 l18n 子文件夹进入 / src / config / 文件夹,因此,当我执行上一个JSP页面时,我看到了密钥消息属性文件(例如: ??? emittente_fatt ??? 而不是值发票发行者)
好的,所以我尝试复制并粘贴 l18n 文件夹(及其所有内容)并将其放入第二个Web应用程序的 / src / config /
现在,如果我从Intellij工作到我的视图,我可以看到捆绑的 messages_en.properties 和 messages_it.properties 的链接(CTRL +点击关键字标记如果打开其中一个文件我可以选择。
因此,这些属性文件似乎已正确捆绑到项目中。
问题是,如果我尝试运行我的项目,我仍然会看到密钥,而不是相关的值,我看到这样的事情:
为什么呢?我错过了什么?我怎样才能解决这个问题并正确地将价值看到我的?
修改-1 :
这是desviceation webapp的web.xml 内容(国际化无法正常工作):
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>MY APPLICATION NAME</display-name>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>
<listener>
<listener-class>it.sistinf.ediweb.quartz.QuartzListener</listener-class>
</listener>
<servlet>
<servlet-name>edimon</servlet-name>
<servlet-class>it.sistinf.ediweb.monitor.servlets.Monitoraggio</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>edimon</servlet-name>
<url-pattern>/edimon.do/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>salwf</servlet-name>
<servlet-class>it.sistinf.ediweb.monitor.servlets.Salwf</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>salwf</servlet-name>
<url-pattern>/salwf.do/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/logon.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/displaytag-11.tld</taglib-location>
</taglib>
</web-app>
这是我的整个JSP页面:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<jsp:useBean id="Bean_Dati" scope="session" type="it.sistinf.ediweb.dbutil.GestoreDati"/>
<%@ taglib uri="/WEB-INF/displaytag-11.tld" prefix="display" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page import="it.sistinf.ediweb.util.Utility" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="it.sistinf.ediweb.model.RequestCharge" %>
<link rel="stylesheet" href="css/displaytag.css"/>
<link rel="stylesheet" href="css/font.css"/>
<LInk rel="stylesheet" href="css/webedi_thema.css">
<%--<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/ui-darkness/jquery-ui.css" rel="stylesheet">--%>
<LInk rel="stylesheet" href="css/jquery.ui.theme5.css">
<link rel="stylesheet" href="css/claro.css">
<LInk rel="stylesheet" href="css/dataTables/datatable.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery.dataTables.js"></script>
<%
// Per non far fare il caching...
response.setHeader("pragma", "no-cache");
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "no-cache");
String lingua = (String) javax.servlet.jsp.jstl.core.Config.get(request.getSession(), javax.servlet.jsp.jstl.core.Config.FMT_LOCALE);
request.setAttribute("Autorizza", Bean_Dati.getListaRisultati("ListaCertificazioniNonLette"));
%>
<script>dojoConfig = {parseOnLoad: true}</script>
<script src='js/dojo/dojo.js'></script>
<script>
require(["dijit/Dialog", "dijit/form/TextBox", "dijit/form/Button"]);
</script>
<script type="text/javascript">
function checkAutorizza() {
if (isCheckboxChecked2('item') == false) {
alert('<fmt:message key="no_doc_aut" />');
return false;
} else {
document.getElementById('aut').value = "true";
document.getElementById('notaRifiuto').value = "";
document.forms.inboxform.action = "edi.do?serv=Q.2";
document.forms.inboxform.submit();
return true;
}
}
function checkRifiuta() {
if (isCheckboxChecked2('item') == false) {
alert('<fmt:message key="no_doc_aut" />');
return false;
} else {
document.getElementById('aut').value = "false";
document.forms.inboxform.action = "edi.do?serv=Q.3";
document.forms.inboxform.submit();
return true;
}
}
</script>
<div class="panel-wrapper">
<div class="panel-content">
<form name="inboxform" action="edi.do?serv=Q.2" method=post onsubmit="javascript:return checkAutorizza()">
<input type="hidden" name="autorizza" value="" id="aut">
<input type="hidden" name="notaRifiuto" value="" id="notaRifiuto">
<table id="autorizza" border="0" class="standard-table-cls" style="width: 100%!important">
<thead>
<tr>
<th><input id="myCheck" onclick="changeBoxAll(this)" type="checkbox"></th>
<th></th>
<th><fmt:message key="emittente_fatt"/></th>
<th><fmt:message key="mandataria"/></th>
<th><fmt:message key="id"/></th>
<th><fmt:message key="numero_fatt"/></th>
<th><fmt:message key="data_invio"/></th>
<th><fmt:message key="data_approvazione"/></th>
<th><fmt:message key="data_documento"/></th>
<th><fmt:message key="totale_fattura"/></th>
<th><fmt:message key="stato"/></th>
</tr>
</thead>
<tbody>
<%
//int count = 0;
//List l = (List) Bean_Dati.getListaRisultati("Autorizza");
//List l = (List) Bean_Dati.getListaRisultati("ListaCertificazioniNonLette");
//List l = (List) Bean_Dati.getListaRisultati("ListaCertificazioniNonLette");
List l = (List) request.getSession().getAttribute("requestChargeList");
//String trClass = "odd";
for (Iterator iterator = l.iterator(); iterator.hasNext(); ) {
//String evenOrOdd = "";
RequestCharge ci = (RequestCharge) iterator.next();
//if (trClass.equals("odd")) trClass = "even";
//else trClass = "odd";
/*
if ((count & 1) == 0) {
evenOrOdd = "even";
} else {
evenOrOdd = "odd";
}
count++;
*/
%>
<tr style="cursor:pointer;" onclick="">
<td>
<%if (ci.isAutorizza() && ci.isMaster()) {%>
<input class="myCheck" name="item" type="checkbox" id="<%=ci.getPk_coda()%>"
value="<%=ci.getPk_coda()%>"
<%}%></td>
<td>
<%if (ci.isAutorizza() && ci.isMaster()) {%>
<img
onclick="changeBoxAll2(document.getElementById('myCheck')); openDialog('edi.do?serv=3.B&pk='+'<%=ci.getPk_coda()%>'+'&canale=WEB&autorizza=si','680px','500px','9')"
width="16px" src="img/icona_vedidocumento.png" align=left border=0 alt="Visualizza">
<%} else {%>
<img
onclick="openDialog2('edi.do?serv=3.B&pk='+'<%=ci.getPk_coda()%>'+'&canale=WEB&autorizza=no','680px','500px','9')"
width="16px" src="img/icona_vedidocumento.png" align=left border=0 alt="Visualizza">
<%}%>
</td>
<td><%=ci.getDesc_unita1()%>
</td>
<td><%=(ci.getFornitore() != null ? ci.getFornitore() : (String) request.getSession().getAttribute("mandataria"))%>
</td>
<td><%=ci.getPk_coda()%>
</td>
<td><%=ci.getNum_doc()%>
</td>
<td><%=(ci.getData_in() != null ? ci.getData_in().substring(8, 10) + "/" + ci.getData_in().substring(5, 7) + "/" + ci.getData_in().substring(0, 4) : "") %>
</td>
<td><%=(ci.getData_app() != null ? ci.getData_app().substring(8, 10) + "/" + ci.getData_app().substring(5, 7) + "/" + ci.getData_app().substring(0, 4) : "")%>
</td>
<td><%=(ci.getData_doc() != null ? ci.getData_doc().substring(8, 10) + "/" + ci.getData_doc().substring(5, 7) + "/" + ci.getData_doc().substring(0, 4) : "")%>
</td>
<td align="right"><%=(ci.getTot_fattura()!=null?Utility.getImportFormatLanguage(ci.getTot_fattura(), lingua):"")%></td>
<td title="<%=(ci.getMotivoRifiuto()!=null?ci.getMotivoRifiuto():"")%>"><%=ci.getStato()%>
</td>
</tr>
<%} %>
</tbody>
</table>
</form>
<% if (Bean_Dati.getNumeroRecord("Autorizza") != 0) {%>
<div class="bottoneDiv">
<input class="bottone" readonly="readonly" type="text" value="<fmt:message key="autorizza" />"
onclick="Javascript: checkAutorizza();"/>
<%--<input class="bottone" readonly="readonly" type="text" value="<fmt:message key="rifiuta" />"--%>
<%--onclick="Javascript: checkRifiuta();"/>--%>
</div>
<% } %>
<div id="dialog" title="">
<iframe scrolling="no" frameborder="0" width="100%" height="630px" src="" id="myFrame">
</iframe>
</div>
<div id="dialogReject" title="">
<%--<iframe scrolling="no" frameborder="0" width="100%" height="200px" src="" id="myFrameReject">--%>
<table style="visibility: hidden;" id="rifiutaTable" border="0" class="standard-table-cls"
style="width: 100%!important">
<thead>
<tr>
<th>Inserire note ri rifiuto</th>
</tr>
</thead>
<tr>
<td>
<textarea style="visibility: hidden;" rows="5" cols="50" id="myRejectNote"></textarea>
</td>
</tr>
<tr>
<td>
<input class="bottone" readonly="readonly" type="text" value="<fmt:message key="rifiuta" />"
onclick="rifiuta()"/>
</td>
</tr>
</table>
<%--</iframe>--%>
</div>
</div>
</div>
答案 0 :(得分:1)
您的JSP需要两个taglib:
<%@ taglib uri="/WEB-INF/displaytag-11.tld" prefix="display" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
您的web.xml未加载第二个taglib - 必须如下所示并包含两个taglib条目:
<taglib>
<taglib-uri>http://displaytag.sf.net</taglib-uri>
<taglib-location>/WEB-INF/displaytag-11.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/lib/fmt.tld</taglib-location>
</taglib>
并提供包含WEB-INF/lib
。
fmt.tld