J2EE社區

          茍有恒,何必三更起五更眠;
          最無益,只怕一日曝十日寒.
          posts - 241, comments - 318, trackbacks - 0, articles - 16

          動態傳參 中文編碼 信息提示處理

          Posted on 2010-06-25 00:53 xcp 閱讀(562) 評論(0)  編輯  收藏 所屬分類: JAVA
          一、服務端兩種處理中文的方式
              1.Action寫法
              
          private String showMessage; //公有屬性

          //第一種處理編碼方式
          this.showMessage = URLEncoder.encode("刪除所有采集數據成功!!""UTF-8");   

           //第二種處理編碼方式
           BASE64Encoder encode 
          = new BASE64Encoder();
          this.showMessage = encode.encode("數據成功!!".getBytes("UTF-8"));
               return "toPromp";

              2.strutx.xml
              
              <global-results>
                      
          <result name="error" type="redirect">/common/500.jsp</result>
                      
          <result name="notFund" type="redirect">/common/404.jsp</result>
                      
          <result name="toPromp" type="redirect">/common/prompt.jsp?source=${source}&amp;showMessage=${showMessage}</result>
                  
          </global-results>


             3.前臺頁面
          <%@ page language="java" pageEncoding="UTF-8"%>
          <%@page import="sun.misc.BASE64Decoder"%>
          <%@ taglib prefix="s" uri="/struts-tags"%>
          <%
              String path 
          = request.getContextPath();
              String basePath 
          = request.getScheme() + "://"
                      
          + request.getServerName() + ":" + request.getServerPort()
                      
          + path + "/";
          %>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
              
          <head>
                  
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                  
          <title>信息提示</title>
                  
          <base href="<%=basePath %>">
                  
          <STYLE type="text/css">
                      a                        
          { text-decoration: none; color: #002280 }
                      a:hover              
          { text-decoration: underline }
                      body                  
          { font-size: 9pt; }
                      table                   
          { font: 9pt Tahoma, Verdana; color: #000000 }
                      .header               
          { font: 9pt Tahoma, Verdana; color: #FFFFFF; font-weight: bold; background-color: #98D745 }
                      .header a            
          { color: #FFFFFF }
                      .tableborder        
          { background: #CDE2F8; border: 1px solid #98D745 } 
                  
          </STYLE>
                  
          <SCRIPT language=javascript> 
                      var secs
          =3;//3秒
                      for(i=1;i<=secs;i++
                      

                          window.setTimeout(
          "update(" + i + ")", i * 1000);}
           
                          function update(num) 
                          

                              
          if(num == secs) 
                              

                                  window.location.href
          ="<%=basePath %><s:property value="#parameters.source"/>";
                              }
           
                      }

                  
          </SCRIPT>
              
          </head>

              
          <body>
                  
          <br>
                  
          <br>
                  
          <br>
                  
          <br>
                  
          <br>
                  
          <br>
                  
          <table width="500" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
                      
          <tr class="header">
                          
          <td height="25">
                              
          <div align="center">
                                  信息提示
                              
          </div>
                          
          </td>
                      
          </tr>
                      
          <tr bgcolor="#FFFFFF">
                          
          <td height="80">
                              
          <div align="center">
                                  
          <br>
                                  
          <b>
                                      
          <%
                                          BASE64Decoder d 
          = new BASE64Decoder();
                                          String temp 
          =  new String(d.decodeBuffer(request.getParameter("showMessage")), "UTF-8"
          );
                                          out.println(temp);

                                       
          %>
                                  
          </b>
                                  
          <br>
                                  
          <br>
                                  
          <a href="<s:property value="#parameters.source"/>">如果您的瀏覽器沒有自動跳轉,請點擊這里</a>
                                  
          <br>
                                  
          <br>
                              
          </div>
                          
          </td>
                      
          </tr>
                  
          </table>
              
          </body>
          </html>

           

          <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
          <%@page import="java.net.URLDecoder"%>
          <%@ taglib prefix="s" uri="/struts-tags"%>
          <%
              String path 
          = request.getContextPath();
              String basePath 
          = request.getScheme() + "://"
                      
          + request.getServerName() + ":" + request.getServerPort()
                      
          + path + "/";
          %>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
              
          <head>
                  
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                  
          <title>信息提示</title>
                  
          <base href="<%=basePath %>">
                  
          <STYLE type="text/css">
                      a                        
          { text-decoration: none; color: #002280 }
                      a:hover                    
          { text-decoration: underline }
                      body                    
          { font-size: 9pt; }
                      table                    
          { font: 9pt Tahoma, Verdana; color: #000000 }
                      .header                    
          { font: 9pt Tahoma, Verdana; color: #FFFFFF; font-weight: bold; background-color: #98D745 }
                      .header a                
          { color: #FFFFFF }
                      .tableborder            
          { background: #CDE2F8; border: 1px solid #98D745 } 
                  
          </STYLE>
                  
          <SCRIPT language=javascript> 
                      var secs
          =2;//2秒
                      for(i=1;i<=secs;i++
                      

                          window.setTimeout(
          "update(" + i + ")", i * 1000);}
           
                          function update(num) 
                          

                              
          if(num == secs) 
                              

                                  window.location.href
          ="<%=basePath %><s:property value="#parameters.source"/>";
                              }
           
                      }

                  
          </SCRIPT>
              
          </head>

              
          <body>
                  
          <br>
                  
          <br>
                  
          <br>
                  
          <br>
                  
          <br>
                  
          <br>
                  
          <table width="500" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
                      
          <tr class="header">
                          
          <td height="25">
                              
          <div align="center">
                                  信息提示
                              
          </div>
                          
          </td>
                      
          </tr>
                      
          <tr bgcolor="#FFFFFF">
                          
          <td height="80">
                              
          <div align="center">
                                  
          <br>
                                  
          <b>
                                      
          <%
                                          String temp 
          = URLDecoder.decode(request.getParameter("showMessage"),"utf-8");
                                          out.println(temp);
                                       
          %>
                                  
          </b>
                                  
          <br>
                                  
          <br>
                                  
          <a href="<s:property value="#parameters.source"/>">如果您的瀏覽器沒有自動跳轉,請點擊這里</a>
                                  
          <br>
                                  
          <br>
                              
          </div>
                          
          </td>
                      
          </tr>
                  
          </table>
              
          </body>
          </html>



          弄了半天,還是解決不了問題,把改配置的都配了,為什么還是不行呢,我暈,最好才發現,Tomcat服務器下,不支持瀏覽器帶中文,需要設置一個東西 就是Service里面設置 :
           
           <Connector port="8080" protocol="HTTP/1.1" 
                     connectionTimeout
          ="20000" 
                     redirectPort
          ="8443" 
                     URIEncoding
          ="UTF-8"/>



          名稱: ?4C.ESL | .↗Evon
          口號: 遇到新問題?先要尋找一個方案乄而不是創造一個方案こ
          mail: 聯系我


          主站蜘蛛池模板: 青河县| 南和县| 孟村| 夏河县| 双峰县| 金溪县| 石阡县| 舞钢市| 宁城县| 丰县| 玛曲县| 太保市| 双鸭山市| 拉孜县| 闵行区| 南阳市| 大埔县| 宾阳县| 巧家县| 丰镇市| 西藏| 潞西市| 仁寿县| 浦北县| 额济纳旗| 贡觉县| 遂川县| 达孜县| 贵溪市| 洛隆县| 阜宁县| 郴州市| 巨鹿县| 龙岩市| 阳朔县| 壤塘县| 道真| 喀喇沁旗| 吉水县| 垦利县| 湖州市|