欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
"struts中文問(wèn)題","struts國際化問(wèn)題"的終極解決方案
Java本身就支持多國語(yǔ)言編碼,不需要寫(xiě)任何程序,可以很簡(jiǎn)單的 
實(shí)現。 
秘訣就是兩點(diǎn): 

 

1、所有HTML/JSP頁(yè)面全部采用UTF-8編碼 

2、客戶(hù)端瀏覽器完全支持UTF-8編碼 

步驟: 
1、首先把所有的HTML/JSP的ContentType都設為UTF-8 

2、然后對于JSP程序中的非ASCII碼提示信息都不應該寫(xiě)在程序里面,都應該放在 
application.properties里面統一管理。 

3、對HTML用native2ascii工具統一做一次處理,把HTML中的非ASCII碼都轉換為Unicode編碼。 

4、針對不同的語(yǔ)言,寫(xiě)不同的application.properties,比如說(shuō)簡(jiǎn)體中文是 
application_zh_CN.properties,繁體中文是application_zh_TW.properties這樣,然后對這些配置信 
息文件同樣用native2ascii工具處理一次,把非ASCII碼統統轉為Unicode編碼。 

5、在Servlet的request.getCharacterEncoding()獲得客戶(hù)端的操作系統默認編碼,然后set到Struts 
的HTTPSession的Locale中。 

OK!現在不同的客戶(hù)訪(fǎng)問(wèn),就會(huì )顯示不同的語(yǔ)言版本了。你可以看看此時(shí)你的瀏覽器的字符集,就是 
UTF-8?,F在你的網(wǎng)站和Google一樣了,嘿嘿,其實(shí)你有心的話(huà),看看你的瀏覽器訪(fǎng)問(wèn)Google的時(shí)候是 
什么字符集吧 

切記:所有的HTML/JSP都要設為UTF-8編碼,所有的文件中的非ASCII碼字符都要用native2ascii工具轉 
為用ASCII表示的Unicode編碼。 
----------------------------------------
上面所述是我從網(wǎng)上下的一篇于中文問(wèn)題的解決方案,確切的說(shuō)應該是關(guān)于Struts的國際化問(wèn)題,下面我結合我的實(shí)踐談?wù)劸唧w如何實(shí)現Struts的國際化問(wèn)題,我對理論不是非常精通,我只能完全憑自己的理解和實(shí)踐來(lái)講述,所以下面講的內容可能不是非常正確,還請大家原諒。但有一點(diǎn)可以肯定,我通過(guò)自己的努力解決了Struts的中文問(wèn)題,并實(shí)現Struts的國際化,其實(shí)一切并不復雜,下面是具體步驟:

  0.遇到的問(wèn)題(這些問(wèn)題也許不會(huì )同時(shí)出現)
    a.中文數據從數據庫中到j(luò )sp中后就變成了"????"
    b.做好的中文properties文件,其中的中文value在頁(yè)面顯示亂碼
    c.jsp文件中的中文到瀏覽器后顯示時(shí)也是亂碼(建議不要在jsp文件中輸入中文,盡量放在properties文件中)
    d.由jsp傳給bean的中文值,再由bean傳回頁(yè)面又是亂碼
    e.當更換本地瀏覽器的語(yǔ)言選項時(shí),Web應用程序不能自動(dòng)根據你的locale選擇合適的*.properties文件。導致Web應用程序不能?chē)H化。
  1.環(huán)境:
      Web服務(wù)器: Tomcat 5.0.19
       操作系統: Win2000 Server
         JVM   : jdk 1.4
       數 據 庫: Oracle 8.1.7
       開(kāi)發(fā)工具: struts studio 5.2 pro   for  eclipse
  2.先將所有*.jsp 網(wǎng)頁(yè)中開(kāi)頭處加入

    <%@ page language="java" contentType="text/html; charset=utf-8" %>
     再設置<html:html locale = "true">

  3.然后編輯好兩個(gè)*.properties文件,放在classes文件夾下你指定的地方,這里是放在/web-inf/classes/com/wiley 下,它們分別是:

    ApplicationResources.properties  (英文資源文件)
    ApplicationResources_zh.properties (中文資源文件)
    隨便用什么工具編寫(xiě)都行??!
  4.將ApplicationResources_zh.properties轉碼成gb2312。上面引文說(shuō)要轉成UTF-8,結果我試了,不行。轉成gb2312就行了,操作是。
    將ApplicationResources_zh.properties更名為ApplicationResources_xx.properties
    在DOS命令行進(jìn)入ApplicationResources_xx.properties所在的文件夾
    使用命令:native2ascii -encoding gb2312 ApplicationResources_xx.properties ApplicationResources_zh.properties(至于你為什么會(huì )出現“native2ascii不是內部命令”,,請查其它資料,可能你要設置環(huán)境變量,因為他是jdk的文件夾bin下的一個(gè)應用程序)
   5.接下來(lái)配置struts-config.xml,很簡(jiǎn)單,我們加入:

   <message-resources parameter="com.wiley.ApplicationResources"/>  就行了;

   到此已能解決大多數中文問(wèn)題。如上面所說(shuō)的a,b,e 現在打開(kāi)瀏覽器,選擇菜單:工具》internet選項》語(yǔ)言,將“中文-中國[zh-cn]”刪掉,添加一個(gè)“英語(yǔ)-英國[zh-gb]”確定后,重啟Tomcat,輸入網(wǎng)址你就會(huì )發(fā)現,你的頁(yè)面的文本信息就會(huì )用的是ApplicationResources.properties  (英文資源文件)中的內容。如果換回“中文-中國[zh-cn]”,它就會(huì )顯示ApplicationResources_zh.properties (中文資源文件)中的中文內容。

  至于問(wèn)題“c.jsp文件中的中文到瀏覽器后顯示時(shí)也是亂碼” 你就要用與第4步類(lèi)似的方法來(lái)重新對*.jsp 文件編碼,這時(shí)-encoding的參數就要用UTF-8了,如果你用的也是struts studio 5.2 pro   for  eclipse工具,這一步就免了。它會(huì )自動(dòng)用UTF-8的格式存儲。
  至于問(wèn)題“d.由jsp傳給bean的中文值,再由bean傳回頁(yè)面又是亂碼”的解決,我只是加了個(gè)過(guò)濾器。
你可以現在web.xml中加入:
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.wiley.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>  
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>

  然后在你指定的包內加個(gè)java文件 我放在了/web-inf/classes/com/wiley 里,下面是源代碼:
/*
* XP Forum

* Copyright (c) 2002-2003 RedSoft Group. All rights reserved.
*
*/
package com.huahang.tj.struts.filters;

import javax.servlet.*;
import java.io.IOException;

/**
* <p>Filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding. Configuration of this filter is based on
* the following initialization parameters:</p>
* <ul>
* <li><strong>encoding</strong> - The character encoding to be configured
* for this request, either conditionally or unconditionally based on
* the <code>ignore</code> initialization parameter. This parameter
* is required, so there is no default.</li>
* <li><strong>ignore</strong> - If set to "true", any character encoding
* specified by the client is ignored, and the value returned by the
* <code>selectEncoding()</code> method is set. If set to "false,
* <code>selectEncoding()</code> is called <strong>only</strong> if the
* client has not already specified an encoding. By default, this
* parameter is set to "true".</li>
* </ul>
*
* <p>Although this filter can be used unchanged, it is also easy to
* subclass it and make the <code>selectEncoding()</code> method more
* intelligent about what encoding to choose, based on characteristics of
* the incoming request (such as the values of the <code>Accept-Language</code>
* and <code>User-Agent</code> headers, or a value stashed in the current
* user‘s session.</p>
*
* @author <a href="mailto:jwtronics@yahoo.com">John Wong</a>
*
* @version $Id: SetCharacterEncodingFilter.java,v 1.1 2002/04/10 13:59:27 johnwong Exp $
*/
public class SetCharacterEncodingFilter implements Filter {

// ----------------------------------------------------- Instance Variables


/**
* The default character encoding to set for requests that pass through
* this filter.
*/
protected String encoding = null;


/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;


/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;


// --------------------------------------------------------- Public Methods


/**
* Take this filter out of service.
*/
public void destroy() {

this.encoding = null;
this.filterConfig = null;

}


/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {

// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}

// Pass control on to the next filter
chain.doFilter(request, response);

}


/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
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 Methods


/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* <code>null</code>.
* <p>
* The default implementation unconditionally returns the value configured
* by the <strong>encoding</strong> initialization parameter for this
* filter.
*
* @param request The servlet request we are processing
*/
protected String selectEncoding(ServletRequest request) {

return (this.encoding);

}

}//EOC
   到此我遇到的中文問(wèn)題已全部得到解決,并從中理解到struts的國際化的深刻含義。
我個(gè)人覺(jué)得struts作為一個(gè)功能強大的應用框架,應該早就考慮到它的國際化問(wèn)題,并在實(shí)際應用中不會(huì )很復雜,只要我們遵循一些規則,就可以盡情享受struts給我們帶來(lái)的無(wú)窮樂(lè )趣。希望以上所述對大家有所幫助。


方案二


 

Struts國際化處理一

一種Struts國際化處理的思路- -

                                      

一、Struts的國際化
    Struts是一種支持國際化的MVC的Web Framework??墒侨绾蝸?lái)使用struts國際化是一個(gè)問(wèn)題。下面我們來(lái)探討一下,如何實(shí)現Struts的國際化。Web程式的國際化涉及到3個(gè)層面的東西。第一、jsp部分的輸入/輸出;第二、應用處理程序的國際化;第三、DB的國際化問(wèn)題。這里主要探討的是jsp部分的輸入/輸出問(wèn)題。

二、靜態(tài)部分的國際化
   Struts的jsp頁(yè)面靜態(tài)內容(包括靜態(tài)文字,靜態(tài)圖片)國際化問(wèn)題,是通過(guò)資源文件來(lái)實(shí)現的。要實(shí)現國際化,需要做如下幾項工作:1、定義web.xml的動(dòng)ActionServlet的參數;2、定義資源文件;3、定義JSP頁(yè)面的字符集合;4、在JSP頁(yè)面獲取資源文件里面的內容。
1、定義web.xml的動(dòng)ActionServlet的參數
<servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>   
  <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
  </init-param>
 
<init-param>
    <param-name>application</param-name>
    <param-value>ApplicationResources</param-value> <!-- 默認資源文件名 -->
  </init-param>
  <load-on-startup>2</load-on-startup>
</servlet>

2、定義資源文件
在/WEB-INF/classes下面添加UTF-8資源束文件。每一個(gè)資源文件是“鍵-值”對的集合。在JSP頁(yè)面里面可以通過(guò)鍵來(lái)找到相應的數據值。本例子的文件名是ApplicationResources,所以相應的資源文件束是(包括e文,簡(jiǎn)體中文,繁體中文)
ApplicationResources.properties : 默認資源文件。當在其他資源文件里面找不到某個(gè)資源的時(shí)候,就使用該資源文件里面的定義。
ApplicationResources_zh_CN.properties:簡(jiǎn)體中文資源文件。
ApplicationResources_zh_TW.properties:繁體中文資源文件。
資源文件的格式為:默認資源文件名_國別_語(yǔ)言.properties。其中每個(gè)文件都是通過(guò)%JAVA_HONE%/BIN/native2ascii.exe工具轉換而來(lái)。你也可以使用其他工具來(lái)處理得到(
http://java.sun.com/products/jilkit/ 有一個(gè)工具Internationalization Java Internationalization and Localization Toolkit 可以處理)。下面是一個(gè)例子,我們顯示如何使用%JAVA_HONE%/BIN/native2ascii.exe命令來(lái)定義資源束文件。
2.1 準備文件
//ApplicationResources.properties ;默認資源文件,通常里面的內容是英文的。
label.username=USERNAME :
label.password=PASSWORD :

//ApplicationResources_zh_CN.bak ;簡(jiǎn)體中文的資源文件。里面的內容是中文的。它需要工具將其中的內容處理成UTF-8
label.username=用戶(hù)名 :
label.password=密  碼 :

//ApplicationResources_zh_TW.bak : 繁體中文的資源文件。里面的內容是中文的。它需要工具將其中的內容處理成UTF-8,下面的內容是繁體碼。
label.username=ノめ?W :
label.password=ノめ?W :

2.2 準備完成以后,使用如下的命令創(chuàng )建UTF-8資源文件束
native2ascii -encoding gb2312 ApplicationResources_zh_CN.bak ApplicationResources_zh_CN.properties
native2ascii -encoding big5 Applica tionResources_zh_TW.bak ApplicationResources_zh_TW.properties

3、定義JSP頁(yè)面的字符集合
定義JSP頁(yè)面的語(yǔ)言為UTF-8。在每個(gè)JSP頁(yè)面,必須有如下的內容(如果使用的模板技術(shù),則只是需要在模板頁(yè)面添加,其他使用該模板的頁(yè)面無(wú)需添加)
<%@ page contentType="text/html;charset=UTF-8"%>

4、在JSP頁(yè)面獲取資源文件里面的內容。
在JSP里面需要顯示靜態(tài)內容的地方使用<bean:message />strus的bean tag包里面的message標簽。例如下面的頁(yè)面

<table>
  <tr>
    <td align="right"><bean:message key="label.username" /></td>   
  </tr>
  <tr>
    <td align="right"><bean:message key="label.password" /></td>
  </tr>
</table>

好了,在這個(gè)頁(yè)面顯示的時(shí)候,如果客戶(hù)的IE的語(yǔ)言集合是zh_CN的話(huà),就會(huì )顯示
用戶(hù)名:
口  令:

如果是客戶(hù)的IE的語(yǔ)言是zh_TW的話(huà),就會(huì )顯示
用戶(hù)名:
用戶(hù)名:

可以在IE的工具->Internet選項->語(yǔ)言的地方,來(lái)選擇,定義IE的語(yǔ)言。

三、表單的數據的處理。
對于表單數據的處理,我們是通過(guò)添加一個(gè)Filter來(lái)實(shí)現的。所有提交的請求,都需要做字符處理。然后在web.xml里面定義該Filter。這樣我們就不需要在程序里面做任何的字符處理。
3.1 定義Filter。下面是一個(gè)例子。
package com.webapps.commons;

import java.io.*;
import javax.servlet.*;

public class CharsetEncodingFilter implements Filter{
  private FilterConfig config = null;
  private String defaultEncode = "UTF-8";

  public void init(FilterConfig config) throws ServletException {
    this.config = config;
    if(config.getInitParameter("Charset")!=null){
        defaultEncode=config.getInitParameter("Charset");
    }
  }

  public void destroy() {
    this.config = null;
  }

  public void doFilter(ServletRequest request, ServletResponse response,
                       FilterChain chain) throws IOException, ServletException {
    ServletRequest srequest=request;
    srequest.setCharacterEncoding(defaultEncode);
    chain.doFilter(srequest,response);
  }
}

3.2 在web.xml里面聲明使用該Filter
<filter>
  <filter-name>Character Encoding</filter-name>
  <filter-class>com.webapps.commons.CharsetEncodingFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>Character Encoding</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

四、擴展
待續的是應用程序部分的國際化問(wèn)題,和DB的國際化問(wèn)題。

Struts國際化處理 二

對于使用者來(lái)說(shuō),一個(gè)支持國際化的WEB程序具有下面幾種形式

1. 根據用戶(hù)瀏覽器自動(dòng)設置顯示的語(yǔ)言(無(wú)需用戶(hù)干預)
2. 提供用戶(hù)選擇,用戶(hù)根據自己的需要決定使用何種語(yǔ)言顯示
3. 結合前兩種.系統自動(dòng)選擇一種語(yǔ)言,但同時(shí)提供用戶(hù)根據需要選擇

使用Struts開(kāi)發(fā)國際化程序是一件非常便利的事情,我們來(lái)看前兩種怎么來(lái)實(shí)現

1. 這是最簡(jiǎn)單的方式,你不需要修改任何程序,只需要把資源文件按照各個(gè)語(yǔ)言翻譯一遍并把這些文件按照國際化程序的要求命名好放置同一個(gè)目錄即可. 例如 ApplicationResource_en_US.properties ApplicationResource_zh_TW.properties . 這種方式雖然自動(dòng)的給用戶(hù)設置好要顯示的語(yǔ)言,但是有時(shí)候由于瀏覽器本身的問(wèn)題,或者用戶(hù)自己想看其他語(yǔ)種的時(shí)候就沒(méi)有辦法.

2. 這是比較常見(jiàn)的方式,由用戶(hù)自己來(lái)選擇所要顯示的語(yǔ)言. 一般的情況是在首頁(yè)或者登錄頁(yè)上增加語(yǔ)言的選項,用戶(hù)選中其中一種登錄后即以用戶(hù)選擇的語(yǔ)言進(jìn)行顯示,但是用戶(hù)登錄后必須把用戶(hù)所選擇的語(yǔ)言保存起來(lái)并讓程序也就是<bean:message這些標簽可以使用所選擇的語(yǔ)言加載配置信息,因此在用戶(hù)登錄執行的Action類(lèi)中加入如下代碼

Locale locale = new Locale(request.getParameter("locale"));
//TODO:判斷locale的有效性,無(wú)效的話(huà)不存入到sesssion中
req.getSession().setAttribute(Globals.LOCALE_KEY,locale);

好了,現在<bean:message/>這個(gè)標簽庫現在就可以根據你保存在session中的Locale對象來(lái)決定加載的是哪種語(yǔ)言, 通過(guò)看<bean:message/>標簽庫的源碼我們就可以一目了然知道該標簽庫在加載資源前先從session或者該Locale對象,如果為空則使用request.getLocale()這個(gè)值來(lái)加載對應語(yǔ)言的資源,因此這種做法實(shí)際上是實(shí)現了前面提到的第三種形式. 接下來(lái)就是翻譯資源文件,有如第一步講到的.

Struts框架在實(shí)現國際化應用程序的時(shí)候還是替我們想的很周到,因此你所需要做的就是翻譯.

最后切記兩點(diǎn):
1. 頁(yè)面的字符集必須是UTF-8,例如:
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
2. 另外頁(yè)面的所有的提示信息都應該在資源文件中定義

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
struts2.1.8 + spring2.5.6 + hibernate3.3.2整合的...
認識struts.i18n.encoding
JSP中文問(wèn)題解決方案超級大總結 (JSP/Servlet 技術(shù))
Java平臺國際編碼問(wèn)題分析_SUN-JAVA技術(shù)
Mysql與JSP網(wǎng)頁(yè)中文亂碼問(wèn)題的解決方案
struts處理中文亂碼問(wèn)題
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久