如何将 UTF8 值设置为 web.xml?

How can I put UTF8 value to web.xml?

我正在考虑将一些 UTF-8 字作为 env-entry-value 放入 web.xml,但不知何故这会导致我的 war 无法部署到我的服务器。我的设置导致部署失败的案例如下所示。

<env-entry>
    <description>Msg text</description>
    <env-entry-name>Msg_Text</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>兔子</env-entry-value>
  </env-entry>

错误消息

10:56:41,498 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-15) JBAS015877: Stopped deployment Test.war (runtime-name: Test.war) in 69ms
10:56:41,920 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015858: Undeployed "Test.war" (runtime-name: "Test.war")
10:56:41,920 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.deployment.unit."Test.war".PARSE

谁能教我怎么做?

======更新======

再次尝试使用分号,&#53F0;,然后出现其他错误

    23:57:43,222 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) JBAS014612: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"Test.war\".PARSE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"Test.war\".PARSE: JBAS018733: Failed to process phase PARSE of deployment \"Test.war\"
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS018014: Failed to parse XML descriptor \"/C:/Windows/System32/content/Test.war/WEB-INF/web.xml\" at [58,24]
    Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'F' (code 70); expected a decimal number.
 at [row,col {unknown-source}]: [58,24]"}}
23:57:44,144 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015877: Stopped deployment Test.war (runtime-name: Test.war) in 915ms
23:57:44,144 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.deployment.unit."Test.war".PARSE

如果我用普通的 ascii 字符填充它,效果很好。我还有什么遗漏吗?

  1. web.xml 必须包含 <?xml version="1.0" encoding="UTF-8"?><?xml version="1.0"?>:任何其他编码都会损坏 Unicode 文本内容。
  2. 在 UTF-8 中编辑 web.xml;像 NotePad++ 这样的程序员编辑器就可以了。
  3. 对于十六进制不要忘记x&#x53F0;.