日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
常見JSP中文亂碼例子及其解決方法

JSP開發(fā)應(yīng)用是,中文亂碼是個比較常見的問題,其根源是:Web容器默認的字符處理編碼是ISO-8859-1。

創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計制作、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的泰安網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

實例一、JSP頁面顯示時

 
 
 
 
  1.  
  2.      
  3.        中文亂碼——JSP頁面顯示時 
  4.      
  5.      
  6.        
     
  7.            
     
  8.            

    木蘭辭擬古決絕詞柬友

     
  9.            

    人生若只如初見,何事秋風悲畫扇。

     
  10.          

    等閑變卻故人心,卻道故人心易變。

     
  11.          

    驪山語罷清宵半,淚雨霖鈴終不怨。

     
  12.          

    何如薄幸錦衣郎,比翼連枝當日愿。

     
  13.         
  14.      
  15.  

運行結(jié)果:

解決方法:為其指定中文字符集,前加入

 
 
 
 
  1. <%@ page contentType="text/html;charset=gb2312" %> 

實例二、JSP頁面?zhèn)鬟f中文參數(shù)時

注冊頁面:

 
 
 
 
  1. <%@ page contentType="text/html;charset=gb2312" %> 
  2.  
  3.      
  4.        中文亂碼——JSP頁面?zhèn)鬟f中文參數(shù)時 
  5.      
  6.      
  7.        

    申請賬號:

     
  8.         
  9.            

    郵箱: 

     

  10.            

    昵稱: 

     

  11.            

    密碼: 

     

  12.            

    性別:  男  

  13.                           女

     

  14.            一句話介紹自己... 
  15.            

     
  16.         
  17.      
  18.  

個人信息頁面:

 
 
 
 
  1. <%@ page contentType="text/html;charset=gb2312" %> 
  2.  
  3.      
  4.        中文亂碼——JSP頁面?zhèn)鬟f中文參數(shù)時  
  5.      
  6.      
  7.        
     
  8.            

    用戶信息:

     
  9.            <% String email = request.getParameter("email"); %> 
  10.            <% String nickname = request.getParameter("nickname"); %> 
  11.            <% String password = request.getParameter("password"); %> 
  12.            <% String sex = request.getParameter("sex"); %> 
  13.            <% String introduction = request.getParameter("introduction");%> 
  14.            

    郵箱: <% out.print(email); %>

     

  15.            

    昵稱: <% out.print(nickname); %>

     

  16.            

    密碼: <% out.print(password); %>

     

  17.            

    性別: <% out.print(sex); %>

     

  18.            

    個人介紹:<%out.print(introduction); %>

     
  19.         
  20.      
  21.  

運行結(jié)果:

解決方法:修改個人信息頁面如下

 
 
 
 
  1. <%@ page contentType="text/html;charset=gb2312" %> 
  2.  
  3.      
  4.        中文亂碼——JSP頁面?zhèn)鬟f中文參數(shù)時  
  5.      
  6.      
  7.        

    用戶信息:

     
  8.        <% String email = newString(request.getParameter("email").getBytes("ISO-8859-1"), "gb2312");%> 
  9.        <% String nickname = newString(request.getParameter("nickname").getBytes("ISO-8859-1"), "gb2312");%> 
  10.        <% String password = newString(request.getParameter("password").getBytes("ISO-8859-1"), "gb2312");%> 
  11.        <% String sex = newString(request.getParameter("sex").getBytes("ISO-8859-1"), "gb2312");;%> 
  12.        <% String introduction = newString(request.getParameter("introduction").getBytes("ISO-8859-1"), "gb2312");;%> 
  13.        

    郵箱: <% out.print(email); %>

     

  14.        

    昵稱: <% out.print(nickname); %>

     

  15.        

    密碼: <% out.print(password); %>

     

  16.        

    性別: <% out.print(sex); %>

     

  17.        

    個人介紹:<%out.print(introduction); %>

     
  18.      
  19.  

實例三、Servlet處理中文參數(shù)時

注冊頁面:

 
 
 
 
  1. <%@ page contentType="text/html;charset=gb2312" %> 
  2. <%@ page import="test.UserMsg"%> 
  3.  
  4.      
  5.        中文亂碼——JSP頁面?zhèn)鬟f中文參數(shù)時 
  6.      
  7.      
  8.        

    申請賬號:

     
  9.         
  10.            

    郵箱: 

     

  11.            

    昵稱: 

     

  12.            

    密碼: 

     

  13.            

    性別:  男  

  14.                           女

     

  15.            一句話介紹自己... 
  16.            

     
  17.         
  18.      
  19.  

UserMsg.java(Servlet)

 
 
 
 
  1. package test;  
  2.    
  3. importjava.io.IOException;  
  4. importjava.io.PrintWriter;  
  5. importjava.io.UnsupportedEncodingException;  
  6.    
  7. importjavax.servlet.http.HttpServlet;  
  8. importjavax.servlet.http.HttpServletRequest;  
  9. importjavax.servlet.http.HttpServletResponse;  
  10. public classUserMsg extends HttpServlet{  
  11.       public void doGet(HttpServletRequestrequest,  
  12.                  HttpServletResponse response){  
  13.            doPost(request, response);  
  14.       }  
  15.       public void doPost(HttpServletRequestrequest,  
  16.                  HttpServletResponse response){  
  17.            try {  
  18.                  request.setCharacterEncoding("gb2312");  
  19.            } catch (UnsupportedEncodingExceptione) {  
  20.                  e.printStackTrace();  
  21.            }  
  22.            PrintWriter out = null;  
  23.            try {  
  24.                  out = response.getWriter();  
  25.            } catch (IOException e1) {  
  26.                  e1.printStackTrace();  
  27.            }  
  28.            out.print("");  
  29.            out.print("");  
  30.            out.print("

    " +"用戶信息:"+ "

    ");  
  31.            out.print("

    "+"郵箱:"+request.getParameter("email")+"

    ");  

  32.            out.print("

    "+"昵稱:"+request.getParameter("nickname")+"

    ");  

  33.            out.print("

    "+"密碼:"+request.getParameter("password")+"

    ");  

  34.            out.print("

    "+"性別:"+request.getParameter("sex")+"

    ");  

  35.            out.print("

    "+"個人介紹:"+request.getParameter("introduction")+"

    ");  

  36.            out.print("");  
  37.            out.print("");  
  38.       }  

運行結(jié)果:

解決方法:在doPost中加入:

 
 
 
 
  1. response.setContentType("text/html; charset=gb2312"); 

網(wǎng)站名稱:常見JSP中文亂碼例子及其解決方法
網(wǎng)頁地址:http://www.dlmjj.cn/article/dhosjoo.html