posts - 495,  comments - 11,  trackbacks - 0

          這時web.xml中相應(yīng)的地方就改為:

          <filter>

          ???????<filter-name>struts</filter-name>

          ???????<filter-class>

          ???????????com.filter.NewFilterDispatcher

          ???????</filter-class>

          ???????<init-param>

          ????????????<param-name>encoding</param-name>

          ????????????<param-value>GB2312</param-value>

          ????????</init-param>

          ????</filter>

          ????

          ????<filter-mapping>

          ???????<filter-name>struts</filter-name>

          ???????<url-pattern>/*</url-pattern>

          ????</filter-mapping>

          說明

          (1)該類是FilterDispatcher類的子類。

          (2)該類有個成員變量,名為encoding,默認(rèn)是“GB<?xml:namespace prefix = st1 />2312

          (3)注意在web.xml中,<filter>標(biāo)簽里多了<init-param>標(biāo)簽,顧名思義,它的作用是初始化一個參數(shù),里面定義了參數(shù)名和參數(shù)值。因此,在子類中,需要重寫init方法,其中:

          String encodingParam = filterConfig.getInitParameter("encoding");

          ???就是從web.xml中讀出了參數(shù)名為encoding的值,然后賦給子類中的encoding成員。

          (4)重寫dofilter方法,加上:

          ??request.setCharacterEncoding(encoding);

          然后再調(diào)用父類的dofilter方法,這樣就完成了編碼的轉(zhuǎn)換。

          (5)如果需要使用其它編碼(如“UTF-8等),只要改變<param-value>中的值即可。

          這樣就把struts2.0加入到工程中了。

          三、Struts2.0的配置文件

          除了在web.xml中配置以外,struts2.0還有幾個自己的配置文件,其中最重要的兩個是struts.propertiesstruts.xml都要放到src目錄下

          Struts.properties的原文件可以在struts-core-2.0.x.jar中找到,原名叫default.properties,將其解壓出來,并改名為struts.properties,放到工程的src目錄下,然后還需要修改里面的值。比如:

          struts.locale=zh_CN

          struts.i18n.encoding=GB2312

          修改以后,這樣struts才能認(rèn)識中文。

          再比如:

          struts.action.extension=action

          這是個默認(rèn)值,意思說,struts的每個action的后綴都是.action

          修改后的struts.properties文件在ftp上。

          Struts.xml文件用于配置所有的action,在后文有詳細(xì)的配置方法。

          四、創(chuàng)建JavaBean

          創(chuàng)建com.bean包,確定需要輸入的個人信息有“姓名”、“性別”、“地址”、“電話”,因此先定義一個JavaBean,名為Person.java,放到com.bean包中,它包括四個成員以及相應(yīng)的getset方法:(待續(xù))

          posted on 2007-09-24 14:48 jadmin 閱讀(93) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 长治市| 宁海县| 南平市| 酒泉市| 稻城县| 宁安市| 麻栗坡县| 利辛县| 吉林省| 舒城县| 广安市| 荣昌县| 沧州市| 全椒县| 东海县| 柳河县| 逊克县| 睢宁县| 克拉玛依市| 黄石市| 象州县| 邛崃市| 龙山县| 浦东新区| 桓台县| 饶阳县| 达州市| 阿尔山市| 辽阳市| 略阳县| 昌邑市| 伊宁市| 监利县| 麟游县| 海兴县| 南安市| 赤壁市| 运城市| 全椒县| 延寿县| 武城县|