这是我的缩小虚拟项目的结构:
./utf8-test
├── index.html
├── META-INF
│ ├── MANIFEST.MF
│ └── maven
│ └── ru.mcmerphy
│ └── utf8-test
│ ├── pom.properties
│ └── pom.xml
├── resources
│ ├── foo.txt
│ └── йцукен.txt
└── WEB-INF
└── glassfish-web.xml
的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schem$
<modelVersion>4.0.0</modelVersion>
<groupId>ru.mcmerphy</groupId>
<artifactId>utf8-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>utf8-test</name>
<properties>
<jdk.version>1.8</jdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>utf8-test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
的glassfish-web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http:$
<glassfish-web-app error-url="">
<locale-charset-map locale="" charset=""/>
<parameter-encoding default-charset="UTF-8" />
</glassfish-web-app>
Glassfish服务器配置(通过管理页面配置):
Network Listeners - URI Encoding: UTF-8
JVM Settings - JVM Options: -Dfile.encoding=utf-8
所以,问题是:
<http://localhost:8080/utf8-test/resources/foo.txt> - Works OK
<http://localhost:8080/utf8-test/resources/йцукен.txt> - 404 Error
除此之外,当我通过管理页面部署所有utf-8字符转换为? 但“jar xf”工作正常。 因此,我的部署步骤是:
系统信息:
BTW在Windows 8.1环境中没有问题。
更新:我使用init脚本:
#!/bin/sh
# /etc/init.d/glassfish
#
### BEGIN INIT INFO
# Provides: glassfish
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start glassfish at boot time
# Description: Enable glassfish.
### END INIT INFO
JAVA_HOME=/opt/jdk1.8.0_40
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
export PATH
case "$1" in
start)
sh /opt/java/glassfish4/bin/asadmin start-database
sh /opt/java/glassfish4/bin/asadmin start-domain
;;
stop)
sh /opt/java/glassfish4/bin/asadmin stop-domain
sh /opt/java/glassfish4/bin/asadmin stop-database
;;
*)
echo "Usage: /etc/init.d/glassfish {start|stop}"
exit 1
;;
esac
exit 0
如果我执行sh glassfish stop
然后sh glassfish start
- 我的问题就会消失。这是什么原因?
答案 0 :(得分:1)
刚刚在init脚本中添加了行export LANG=en_GB.UTF-8
,并且glassfish开始正常工作。