久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

JAVA常見中文問題的解決方案是怎樣的呢-創(chuàng)新互聯(lián)

JAVA常見中文問題的解決方案是怎樣的呢,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

創(chuàng)新互聯(lián)專注于成都網站設計、成都做網站、網頁設計、網站制作、網站開發(fā)。公司秉持“客戶至上,用心服務”的宗旨,從客戶的利益和觀點出發(fā),讓客戶在網絡營銷中找到自己的駐足之地。尊重和關懷每一位客戶,用嚴謹的態(tài)度對待客戶,用專業(yè)的服務創(chuàng)造價值,成為客戶值得信賴的朋友,為客戶解除后顧之憂。

JAVA常見中文問題的解決方法

以下解決方案是筆者在日常生活中遇到的,希望能對你解決JAVA中文問題有所幫助。

1.在jsp頁面首部加上<%@page contenttype="”text/html;charset=GB2312“%">

在servlet中使用httpServlerResponse.setContentTpye(“text/html; charset=GB2312”);可以避免一些中文問題

2.使用JDBC連接mysql數據庫時,連接字符串寫成如下形式可以避免一些中文問題:

jdbc://mysql://hostname:port/DBname?user=username&password=pwd&

useUnicode=true&characterEncoding= iso-8859-1

如果是以數據源的方式連接數據庫在配置文件中使用:

url

jdbc:mysql://hostname:port/DBname? &useUnicode=true&characterEncoding=iso-8859-1

注意要使用&替換&符號,否則XML文件在解析的時候會出錯。

3.從數據庫讀出的數據有可能是亂碼,遇到這種問題可以用如下方法解決:

String desc = rs.getString(“desc”);

desc = new String(desc.getBytes(“ISO-8859-1”),”GB2312”);

4.某個頁面提交中文內容給Servlet,Servlet要對提交的內容進行轉碼工作才能正確接收數據,

通常我們是在servlet中增加以下代碼來解決問題。

httpServlerRequest.setCharacterEncoding(“GB2312”);

5. 在struts中,對資源文件進行轉碼,使用JDK字帶的轉碼工具:

>native2ascii -encoding BG2312 Myresource.properties Myresource_zh.properties

6.在struts中擴展org.apache.struts.action.RequestProcessor類,并覆寫其中的processPreprocess()方法:

package com.mypro.action;

public class MyProRequestProcessor extends RequestProcessor

{

protected boolean processPreprocess (HttpServletRequest request,

HttpServletResponse response)

{

try

{

request.setCharacterEncoding(“GB2312”);

//other code

}

catch(Exception e){}

return true;

}

}

寫完上面代碼別忘了修改struts-config.xml:

7. 用filter實現(xiàn)(推薦)

package com.kefeiannan;

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);

}

}

配置你站點下的web.xml,在后面加上

Set Character Encoding

com.kefeiannan.SetCharacterEncodingFilter

encoding

UTF-8

Set Character Encoding

/*

看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注創(chuàng)新互聯(lián)-成都網站建設公司行業(yè)資訊頻道,感謝您對創(chuàng)新互聯(lián)的支持。

名稱欄目:JAVA常見中文問題的解決方案是怎樣的呢-創(chuàng)新互聯(lián)
網頁鏈接:http://sd-ha.com/article22/ihecc.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供品牌網站設計、ChatGPT、微信小程序App設計、面包屑導航Google

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網站優(yōu)化排名