Get the App
SLTechnology News&Howtos  ›  Development  › 

How to analyze the Chinese problems of JSF

Shulou Source: shulou.com Published: 2022-06-02 06:45:33 10月05日 Update

How to analyze the JSF Chinese problem, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

I encountered a Chinese problem when I started learning JSF. After reading some articles, I suddenly remembered that Struts also had a Chinese problem. I think it should be the same with Filter at that time. Later, the Chinese problem was solved after it was added to the project.

Post the code

Web.xml part

Set Character Encoding

Comm.CN.SetCharacterEncodingFilter

Encoding

GBK

Set Character Encoding

/ *

Javabean part

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)

}

}

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Questions Chinese articles parts learning help analysis clarity code content this engineering novice time more there are Chinese knowledge industry information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Shulou Tech Info Docker Apple