锘??xml version="1.0" encoding="utf-8" standalone="yes"?>欧美在线日韩,jizz日韩,国产精品视频一区二区久久http://www.aygfsteel.com/softwin/category/19404.html蹇瘯涓氫簡 :( 濂藉ソ瀛︿範...澶╁ぉ鍚戜笂 zh-cnTue, 10 Apr 2007 00:46:51 GMTTue, 10 Apr 2007 00:46:51 GMT60Struts2鍏ラ棬鏁欑▼錛岺ello Worldhttp://www.aygfsteel.com/softwin/archive/2007/04/09/109494.html浼借摑浼借摑Mon, 09 Apr 2007 13:14:00 GMThttp://www.aygfsteel.com/softwin/archive/2007/04/09/109494.htmlhttp://www.aygfsteel.com/softwin/comments/109494.htmlhttp://www.aygfsteel.com/softwin/archive/2007/04/09/109494.html#Feedback0http://www.aygfsteel.com/softwin/comments/commentRss/109494.htmlhttp://www.aygfsteel.com/softwin/services/trackbacks/109494.html    褰撲綘鍚戜竴涓鏋舵彁浜TML琛ㄥ崟鐨勬椂鍊欙紝杈撳叆鐨勬暟鎹茍涓嶆槸琚彂閫佸埌涓涓湇鍔$欏甸潰錛岃屾槸浼犻佸埌涓涓綘鑷繁鎻愪緵鐨勭О涓篈ction鐨刯ava綾伙紝浜х敓鐨勭粨鏋滀細閫夋嫨涓涓祫婧愭潵緇樺埗鍝嶅簲銆傝璧勬簮閫氬父涓轟竴涓湇鍔$鐨勯〉闈紝浣嗕篃鍙互鏄竴涓猵df鐨勬枃妗o紝涔熷彲浠ユ槸涓涓狤xcel鐢靛瓙鏁版嵁琛ㄦ牸錛屾垨鑰呮槸Java applet紿楀彛銆?br>    鍋囪浣犲笇鏈涘垱寤轟竴涓畝鍗曠殑“Hello World”渚嬪瓙鏉ユ樉紺烘榪庢秷鎭備笅杞絪truts2鐨勭┖web搴旂敤錛堝嵆struts2-blank-2.0.6.war錛夛紝浣犻渶瑕佸仛浠ヤ笅涓変歡浜嬶細
1.鍒涘緩涓涓湇鍔¢〉闈㈡潵灞曠ず娑堟伅
2.鍒涘緩涓涓狝ction綾繪潵鍒涘緩娑堟伅
3.鍒涘緩涓涓繛鎺ction綾誨拰欏甸潰鐨勬槧灝?br>    璁╂垜浠潵鐪嬬湅榪欎釜Action錛屾湇鍔¢〉闈㈠拰鏄犲皠鐨勪緥瀛愩傚鏋滀綘鍠滄涔熷彲浠ヤ嬌鐢↖DE鏉ョ紪杈戜唬鐮併?br>
浠g爜濡備笅錛?br>棣栧厛錛屽畾涔変竴涓湇鍔¢〉闈㈡樉紺烘暟鎹?br><%@ taglib prefix="s" uri="/struts-tags" %>
<html>
        <head>
                 <title>Hello World!</title>
        </head>
        <body>
                 <h2><s:property value="message" /></h2>
        </body>
</html>
鍏舵錛屾垜浠渶瑕佷竴涓狝ction綾繪潵鍒涘緩娑堟伅
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld extends ActionSupport {
     
       public static final String MESSAGE = "Struts is up and running...";
       
       private String message;

       public String execute() throws Exception {
                setMessage(MESSAGE);
                return SUCCESS;
       }

        public void setMessage(String message) {
                this.message = message;
        }

        public String getMessage() {
                return message;
        }
}
鏈鍚庢垜浠渶瑕佷竴涓槧灝勬潵緇戝畾鎵鏈夈?br>緙栬緫struts.xml鏂囦歡鏉ユ坊鍔燞elloWorld鏄犲皠
<!DOCTYPE struts PUBLIC
           "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
           "<struts>
          <package name="tutorial" extends="struts-default">
                    <action name="HelloWorld" class="tutorial.HelloWorld">
                              <result>/HelloWorld.jsp</result>
                    </action>
          </package>
</struts>
鐒跺悗閮ㄧ講璇ュ簲鐢ㄧ▼搴忥紝鎵撳紑
http://localhost:8080/tutorial/HelloWorld.action瑙傚療鍑虹幇浜嗕粈涔堬紝浣犱細鐪嬭涓涓爣棰樹負Hello World錛佺殑欏甸潰騫舵湁涓涓?#8220;Struts is up and running”鐨勬秷鎭?br>
浠g爜鏄浣曞伐浣滅殑錛?br>1.瀹瑰櫒鎺ユ敹鍒癏elloWorld.action鐨勮姹傘傛牴鎹畐eb.xml鐨勮緗紝瀹瑰櫒浼氬鎵炬墍鏈夎鍙戦佸埌org.apache.struts2.dispatcher.FilterDispatcher鐨勮姹傦紝鍖呮嫭鎵鏈夌殑*.action鐨勮姹傘侳ilterDispatcher鏄鏋剁殑鍏ュ彛鐐廣?br>2.妗嗘灦瀵繪壘涓涓槧灝勫悕涓篐elloWorld鐨凙ction綾匯傚畠鎵懼埌涓嶩elloWorld綾葷浉鍏崇殑鏄犲皠錛屽茍璋冪敤Action鐨別xecute鏂規硶銆?br>3.execute鏂規硶璁劇疆浜嗘秷鎭茍榪斿洖SUCCESS銆傚鏋滆繑鍥炵殑鏄疭UCCESS錛屾鏋朵細媯鏌ction綾繪槧灝勭殑鍝釜欏甸潰灝嗚瑁呰澆銆傛鏋朵細鍛婅瘔瀹瑰櫒緇樺埗HelloWorld.jsp浣滀負璇鋒眰鐨勫搷搴斻?br>4.褰揌elloWorld.jsp琚皟鐢紝<s:property value="message" />鏍囩璋冪敤HelloWorld鐨凙ction綾葷殑getter鏂規硶getMessage錛屽茍灝唌essage鐨勫煎悎騫跺埌鍝嶅簲涓幓銆?br>5.涓涓函綺圭殑鍝嶅簲琚彂閫佸洖嫻忚鍣ㄣ?br>
嫻嬭瘯Actions綾伙紝浠g爜濡備笅
package tutorizl
import junit.framework.TestCase;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class HelloWorldTest extends TestCase {
         public void testHelloWorld() throws Exception {
             
               HelloWorld hello_world = new HelloWorld();
               String results = hello_world.execute();

               assertTrue("Expected a success results!", ActionSupport.SUCCESS.equals(results));
  
               assertTrue("Expected the default message!",HelloWorld.MESSAGE.equals(hello_world.getMessage()));

        }
}

闇瑕佽浣忕殑鏄?妗嗘灦浣跨敤Action綾繪潵澶勭悊HTML琛ㄥ崟鍜屽叾浠栬姹傦紝Action綾昏繑鍥炰竴涓濡係UCCESS,ERROR,鎴朓NPUT鍚嶇О銆傛牴鎹潵鑷猻truts.xml鐨勬槧灝勶紝涓涓繑鍥炵殑鍚嶇О浼氶夋嫨鐩稿簲鐨勯〉闈紝鍙﹀鐨凙ction錛屾垨鍏朵粬web璧勬簮錛堝浘璞★紝PDF錛夈?br>褰撲竴涓湇鍔$欏甸潰琚粯鍒訛紝澶у鎯呭喌涓嬩細鍖呮嫭鐢盇ction綾繪彁渚涚殑鍔ㄦ佹暟鎹傛鏋朵細鎻愪緵涓緋誨垪鐨凥TML鏍囩鍒涘緩欏甸潰鏉ヤ嬌寰楁樉紺哄姩鎬佹暟鎹洿鍔犵畝鍗曘?/p>


 



浼借摑 2007-04-09 21:14 鍙戣〃璇勮
]]>
鍐嶅啓涓閬峴truts瑙e喅涓枃涔辯爜闂http://www.aygfsteel.com/softwin/archive/2006/09/24/71558.html浼借摑浼借摑Sun, 24 Sep 2006 05:30:00 GMThttp://www.aygfsteel.com/softwin/archive/2006/09/24/71558.htmlhttp://www.aygfsteel.com/softwin/comments/71558.htmlhttp://www.aygfsteel.com/softwin/archive/2006/09/24/71558.html#Feedback3http://www.aygfsteel.com/softwin/comments/commentRss/71558.htmlhttp://www.aygfsteel.com/softwin/services/trackbacks/71558.html 鍦ㄥ涔爏truts涓?閬囧埌浜嗕腑鏂囦貢鐮侀棶棰?緗戜笂鎼滅儲浜嗕竴浜涜祫鏂?瑙e喅浜嗛棶棰?/font>

浣跨敤get鏂規硶鏃?闇瑕佷慨鏀?$TOMCAT/conf/server.xml閮ㄧ講鏂囦歡,鍦╟onnectior灞炴т腑娣誨姞URIEncoding="GBK"鍗沖彲

浣跨敤post鏂規硶鏃?鏈?縐嶆柟娉曞彲閫?/font>

1) 瑕嗗啓ActionServlet鐨刾rocess鏂規硶,娣誨姞request.setEncoding("GBK");

2) 娣誨姞涓涓繃婊ゅ櫒SetCharacterEncodingFilter綾?姝ょ被鍙互鍦?TOMCAT\webapps\servlets-examples\WEB-INF\classes\filters鎵懼埌,涓嶈繃鏂逛究璧瘋,鑷繁鍔犱簡鐐逛笢瑗?婧愮爜濡備笅:

public class SetCharacterEncodingFilter implements Filter {
聽private FilterConfig filterConfig;

聽public void destroy()
聽{
聽聽// TODO Auto-generated method stub
聽聽
聽}

聽public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException
聽{
聽聽// TODO Auto-generated method stub
聽聽try{
聽聽聽request.setCharacterEncoding("GB2312");
聽聽聽HttpServletResponse res = (HttpServletResponse)response;
聽聽聽res.setHeader("Pragma", "No-cache");
聽聽聽res.setHeader("Cache-Control", "no-cache");
聽聽聽res.setHeader("Pragram", "no-cache");
聽聽聽filterChain.doFilter(request, response);
聽聽}catch(ServletException e)
聽聽{
聽聽聽filterConfig.getServletContext().log(e.getMessage());
聽聽}catch(IOException e)
聽聽{
聽聽聽filterConfig.getServletContext().log(e.getMessage());
聽聽}
聽}

聽public void init(FilterConfig filterConfig) throws ServletException
聽{
聽聽// TODO Auto-generated method stub
聽聽this.filterConfig = filterConfig;
聽}

}

鍦╳eb.xml涓儴緗茶繖涓繃婊ゅ櫒

<filter>
聽聽聽 <filter-name>servfilter</filter-name>
聽聽聽 <filter-class>com.yourcompany.struts.SetCharacterEncodingFilter</filter-class>
聽 </filter>
聽 <filter-mapping>
聽聽聽 <filter-name>servfilter</filter-name>
聽聽聽 <url-pattern>/*</url-pattern>
聽 </filter-mapping>

鍏充簬鍥介檯鍖栭棶棰?鎴戞浘緇忚鏁欒繃鑰佸笀,涓嶈繃鑰佸笀濂藉儚涓嶆槸榪欎釜鏂瑰悜鐨?/font>

鍚庢潵鎵嶅彂鐜版槸涓涓緢鎰氳牏鐨勯棶棰?瑕佹眰鏄疉pplicationResources_zh_CN.properties鎴朅pplicationResources_zh.properties 鑰屾垜鍗寸敤浜咥pplicationResources_cn.properties

鍒囪CN鏄ぇ鍐欑殑

native2ascii -encoding gb2312 application_temp.properties聽 application_CN.properties

native2ascii鍙互鍦?JAVA_HOME/bin涓嬫壘鍒?/font>



浼借摑 2006-09-24 13:30 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 长阳| 长汀县| 溧水县| 社旗县| 武定县| 博兴县| 延边| 通州区| 安图县| 井研县| 平安县| 玛纳斯县| 扎赉特旗| 新蔡县| 成都市| 剑阁县| 舟曲县| 革吉县| 六枝特区| 屏东县| 鹿泉市| 天峨县| 凤冈县| 宣汉县| 抚州市| 宁阳县| 白城市| 读书| 米脂县| 广汉市| 金山区| 易门县| 龙岩市| 略阳县| 丽水市| 富源县| 保定市| 迁安市| 海安县| 缙云县| 邵阳市|