Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the Chinese problems of JSF

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report