使用javascript函数参数作为spring消息标记参数

Using javascript function arguments as spring message tag arguments

本文关键字:参数 消息 spring javascript 函数 使用      更新时间:2023-09-26

我试图将一个javascript函数参数放入Spring消息中,但失败了。

消息文件条目:

operators.delete.confirm=Are you sure you want to delete {0}?

相关的javascript片段:

var msg = '<spring:message code="operators.delete.confirm" arguments="${username}" javaScriptEscape="true"/>';
console.log ( msg );
console.log ( username );

对于103的用户名,我期望的输出是Are you sure you want do delete 103?,但没有使用参数。控制台日志消息的输出为:

[19:00:14.926] Are you sure you want to delete {0}?
[19:00:14.926] 103

我哪里错了?

我意识到这实际上没有意义。Spring消息标记在服务器上的JSP页面中解析,而javascript变量仅在客户端上可用。