新聞中心
怎樣分析JSF的中文問(wèn)題,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。
開始學(xué)習(xí)JSF的時(shí)候有遇上中文問(wèn)題,看了一些文章后突然想起Struts也有中文問(wèn)題,當(dāng)時(shí)用Filter解決的,我想應(yīng)該也一樣的,后來(lái)在工程里加入后中文問(wèn)題解決了。
貼出代碼
web.xml部分
javabean部分
package comm.CN;
import java.io.IOException;
import javax.servlet.*;
public class SetCharacterEncodingFilter implements Filter
{
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。
網(wǎng)站標(biāo)題:怎樣分析JSF的中文問(wèn)題-創(chuàng)新互聯(lián)
分享鏈接:http://fisionsoft.com.cn/article/doooch.html