JSFは、mavenの環境構築に依存しています。
mavenに依存しますので、pom.xmlファイルを先に配置します。
pom.xmlの配置は以下の通りです。
http://blog.csdn.net/limiteewaltwo/article/details/8796332
web.xmlの構成は以下の通りです。
utf-8符号化を統一して使用し、中国語の文字化け問題を解決します。web.xmlのフィルタは以下の通りです。
入門例、参考
http://blog.csdn.net/limiteewaltwo/article/details/8796352
pom.xmlの配置は以下の通りです。
http://blog.csdn.net/limiteewaltwo/article/details/8796332
web.xmlの構成は以下の通りです。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- -->
<filter>
<filter-name>Character Encoding Filter</filter-name>
<filter-class>com.vs.myjsf.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Character Encoding Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<description>
JSF Demo
</description>
<display-name>JSF Demo</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
faces-config.xml<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>zh_CN</supported-locale>
</locale-config>
</application>
</faces-config>
JSF 2.0では、注釈方式が推奨されていますので、faces-config.xmlは基本的なパラメータだけを配置することを推奨します。utf-8符号化を統一して使用し、中国語の文字化け問題を解決します。web.xmlのフィルタは以下の通りです。
package com.vs.myjsf.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterEncodingFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
chain.doFilter(req, resp);
}
public void init(FilterConfig filterConfig) throws ServletException {
}
public void destroy() {
}
}
設定はほぼ完了しました。入門例、参考
http://blog.csdn.net/limiteewaltwo/article/details/8796352