<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 41,  comments - 8,  trackbacks - 0

    http://prototype.conio.net/dist/

    下載(對(duì)Ajax支持的prototype--js函數(shù)庫(kù)):

     

    http://code.google.com/p/jsonplugin/downloads/list
    下載(Struts2的JSON插件):

      jsonplugin-0.25.jar Struts 2 JSON Plugin 0.25


    第一:手動(dòng)建立項(xiàng)目結(jié)構(gòu)(類(lèi)似于MyEclipse創(chuàng)建Web Pro項(xiàng)目的后臺(tái)操作)


    1、新建文件夾結(jié)構(gòu)如下:
      Struts2json
      |______WEB-INF
                   |_______classes
                   |_______src
                   |_______lib

    2、復(fù)制Tomcat里conf文件夾里的web.xml到WEB-INF文件夾下,并修改web.xml文件
    web.xml文件:

    Xml代碼 復(fù)制代碼
    1. <?xml version="1.0" encoding="ISO-8859-1"?>  
    2.   
    3. <web-app xmlns="http://java.sun.com/xml/ns/javaee"  
    4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee    
    6.     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"   
    7.     version="2.5">  
    8.        
    9. </web-app>  

     

    3、將剛才下載解壓后Struts2下的lib文件夾里
    commons-logging-1.0.4.jar
    freemarker-2.3.8.jar
    ognl-2.6.11.jar
    struts2-core-2.0.11.1.jar
    xwork-2.0.4.jar

    拷貝到Struts2json下lib文件夾里,并將
    jasonplugin-0.25.jar 也拷貝到Struts2json/WEB-INF/lib文件夾下。
    prototype-1.4.0.js 拷貝到Struts2json文件夾下。

    4、找到Strust2里src\apps\showcase\src\main\resources(就是解壓后里面的實(shí)例)的struts.xml文件復(fù)制到Struts2json下classes文件夾下,并修改struts.xml文件 ,或直接在classes文件夾下新建一個(gè)
    struts.xml文件:

    Xml代碼 復(fù)制代碼
    1. <?xml version="1.0" encoding="UTF-8" ?>  
    2. <!DOCTYPE struts PUBLIC   
    3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
    4.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
    5.   
    6. <struts>  
    7.   
    8. </struts>  

     

    5、新建并手寫(xiě)一個(gè)build.xml(必須已經(jīng)安裝了Ant工具),并將build.xml放置到WEB-INF文件夾下 (MyEclipse內(nèi)置了Ant)
    build.xml文件:

    Xml代碼 復(fù)制代碼
    1. <?xml version="1.0"?>  
    2. <project name="struts" basedir="." default="">  
    3.   
    4.     <path id="classpath">  
    5.         <fileset dir="lib">  
    6.             <include name="*.jar"/>  
    7.         </fileset>  
    8.         <pathelement path="."/>  
    9.     </path>  
    10.   
    11.     <target name="compile" description="Compile all source code">  
    12.         <javac destdir="classes" debug="true"  
    13.             deprecation="false" optimize="false" failonerror="true">  
    14.             <src path="src"/>  
    15.             <classpath refid="classpath"/>  
    16.         </javac>  
    17.     </target>  
    18.   
    19. </project>  

     

     

    總結(jié):目錄結(jié)構(gòu)如下
      Struts2t
      |______WEB-INF
                   |_______classes
                    
                 |______struts.xml
                   |_______src
                   |_______lib
                                   |_______ commons-logging-1.0.4.jar
                                   |_______ freemarker-2.3.8.jar
                                   |_______ ognl-2.6.11.jar
                                   |_______ struts2-core-2.0.11.1.jar
                                   |_______ xwork-2.0.4.jar              
                                   |_______ jsonplugin-0.25.jar
                   |_______web.xml
                   |_______build.xml
     |______prototype-1.4.0.js

    ----------------------------------------------------------

    第二:編寫(xiě)核心代碼

    1、Struts2核心就是控制器,為Struts2添加核心Filter配置在web.xml文件中(攔截所有Web請(qǐng)求并由FilterDispatcher初始化)
    web.xml文件:

    Xml代碼 復(fù)制代碼
    1. <?xml version="1.0" encoding="ISO-8859-1"?>  
    2.   
    3. <web-app xmlns="http://java.sun.com/xml/ns/javaee"  
    4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee    
    6.     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"   
    7.     version="2.5">  
    8.        
    9.     <filter>  
    10.         <filter-name>struts2</filter-name>  
    11.         <filter-class>org.apache.Struts2.dispatcher.FilterDispatcher</filter-class>  
    12.     </filter>  
    13.        
    14.     <filter-mapping>  
    15.         <filter-name>struts2</filter-name>  
    16.         <url-pattern>/*</url-pattern>  
    17.     </filter-mapping>  
    18.        
    19. </web-app>  




    2、編寫(xiě)表現(xiàn)層ajaxtest.jsp頁(yè)面并放在與WEB-INF同一級(jí)目錄下。
    ajaxtest . jsp文件:

    Html代碼 復(fù)制代碼
    1. <%@ page language="java" contentType="text/html; charset=GBK"%>  
    2. <script src="prototype-1.4.0.js" type="text/javascript">  
    3. </script>  
    4. <script language="JavaScript">  
    5.     function gotClick()   
    6.     {   
    7.         //請(qǐng)求的地址   
    8.         var url = 'JSONExample.action';   
    9.         //將form1表單域的值轉(zhuǎn)換為請(qǐng)求參數(shù)   
    10.         var params = Form.serialize('form1');   
    11.         //創(chuàng)建Ajax.Request對(duì)象,對(duì)應(yīng)于發(fā)送請(qǐng)求   
    12.         var myAjax = new Ajax.Request(   
    13.         url,   
    14.         {   
    15.             //請(qǐng)求方式:POST   
    16.             method:'post',   
    17.             //請(qǐng)求參數(shù)   
    18.             parameters:params,   
    19.             //指定回調(diào)函數(shù)   
    20.             onComplete: processResponse,   
    21.             //是否異步發(fā)送請(qǐng)求   
    22.             asynchronous:true   
    23.         });   
    24.     }   
    25.     function processResponse(request)   
    26.     {   
    27.         $("show").innerHTML = request.responseText;   
    28.     }      
    29. </script>  
    30. <html>  
    31. <head>  
    32. <title>使用JSON插件</title>  
    33. </head>  
    34. <body>  
    35. <form id="form1" name="form1" method="post">  
    36. <INPUT TYPE="text" name="field1" id="field1"/><br>  
    37. <INPUT TYPE="text" name="field2" id="field2"/><br>  
    38. <INPUT TYPE="text" name="field3" id="field3"/><br>  
    39. <INPUT TYPE="button" value="提交" onClick="gotClick();"/>  
    40. </form>  
    41. <div id="show">  
    42. </div>  
    43. </body>  
    44. </html>  

     

    3、編寫(xiě)POJO(Action)在src下新建文件夾org,在org下新建文件夾jee(這里是建立包名),并新建類(lèi)JSONExample.java放置在src/org/jee文件夾下。

    JSONExample . java文件:

    Java代碼 復(fù)制代碼
    1. package org.jee;   
    2.   
    3. import java.util.HashMap;   
    4. import java.util.Map;   
    5.   
    6. import com.opensymphony.xwork2.Action;   
    7. import com.googlecode.jsonplugin.annotations.JSON;   
    8.   
    9. public class JSONExample   
    10. {   
    11.     private int[] ints = {1020};   
    12.     private Map map = new HashMap();   
    13.     private String customName = "custom";   
    14.   
    15.     private String field1;   
    16.     //'transient'不會(huì)被序列化   
    17.     private transient String field2;   
    18.     //沒(méi)有setter和getter方法的字段不會(huì)被序列化   
    19.     private String field3;   
    20.   
    21.     public String execute()   
    22.     {   
    23.         map.put("name""yeeku");   
    24.         return Action.SUCCESS;   
    25.     }   
    26.   
    27.     public String getField1() {   
    28.         return field1;   
    29.     }   
    30.   
    31.     public void setField1(String field1) {   
    32.         this.field1 = field1;   
    33.     }   
    34.     public String getField2() {   
    35.         return field2;   
    36.     }   
    37.   
    38.     public void setField2(String field2) {   
    39.         this.field2 = field2;   
    40.     }   
    41.   
    42.     public String getField3() {   
    43.         return field3;   
    44.     }   
    45.   
    46.     public void setField3(String field3) {   
    47.         this.field3 = field3;   
    48.     }   
    49.   
    50.     public int[] getInts() {   
    51.         return ints;   
    52.     }   
    53.   
    54.     public void setInts(int[] ints) {   
    55.         this.ints = ints;   
    56.     }   
    57.   
    58.     public Map getMap() {   
    59.         return map;   
    60.     }   
    61.   
    62.     public void setMap(Map map) {   
    63.         this.map = map;   
    64.     }   
    65.   
    66.     @JSON(name="newName")   
    67.     public String getCustomName()    
    68.     {   
    69.         return this.customName;   
    70.     }   
    71. }  



    4、在struts.xml里配置Action,修改classes文件
    struts.xml文件:

    Xml代碼 復(fù)制代碼
    1. <?xml version="1.0" encoding="GBK"?>  
    2. <!DOCTYPE struts PUBLIC   
    3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
    4.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
    5. <struts>  
    6.     <constant name="struts.i18n.encoding" value="UTF-8"/>  
    7.     <package name="example"  extends="json-default">  
    8.         <action name="JSONExample" class="org.jee.JSONExample">  
    9.             <result type="json"/>  
    10.         </action>  
    11.     </package>  
    12.   
    13. </struts>  

    注意:

    第一:配置

    Xml代碼 復(fù)制代碼
    1. <constant name="struts.i18n.encoding" value="UTF-8"/>  

    不使用GBK編碼,而使用UTF-8編碼,因?yàn)锳jax的POST請(qǐng)求都以UTF-8的方式進(jìn)行編碼的。

    第二:配置包時(shí),繼承了json-default包,不再繼承默認(rèn)的default包,因?yàn)橹挥性趈son-default包下才有json類(lèi)型的Result。



    5、將Struts2t整個(gè)文件夾拷貝到Tomcat/webapps文件夾下

    總結(jié):目錄結(jié)構(gòu)如下
      Struts2t
      |______WEB-INF
                   |_______classes
                                  |______org
                                               |_____jee
                                                          |______JSONExample.class
                                  |______struts.xml

                   |_______src
                                  |______org
                                  |_____jee
                                              |______JSONExample.java
                    |_______lib
                                  |_______ commons-logging-1.0.4.jar
                                  |_______ freemarker-2.3.8.jar
                                  |_______ ognl-2.6.11.jar
                                  |_______ struts2-core-2.0.11.1.jar
                                  |_______ xwork-2.0.4.jar  
                                  |_______ jsonplugin-0.25.jar   
                   |_______web.xml
                   |_______build.xml
     |______prototype-1.4.0.js
     |______ajaxtest.jsp

     

    ----------------------------------------------------------

    三、測(cè)試

    1、啟動(dòng)Tomcat6

    2、http://localhost:8080/struts2t (進(jìn)行測(cè)試)

    posted on 2008-10-04 14:19 Loy Fu 閱讀(2058) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): struts

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 自拍偷自拍亚洲精品第1页| 亚洲成人精品久久| 视频免费在线观看| 91亚洲性爱在线视频| 国产无遮挡吃胸膜奶免费看视频| 未满十八私人高清免费影院| 久久久亚洲精品国产| 免费无码又黄又爽又刺激| h在线看免费视频网站男男| 亚洲天堂一区二区| 四虎永久免费影院| 7x7x7x免费在线观看| 亚洲精品色在线网站| 久久精品国产亚洲AV网站| 成人超污免费网站在线看| aa毛片免费全部播放完整| 亚洲一区中文字幕在线电影网| 国产成人免费福利网站| 日韩在线永久免费播放| 国产精品亚洲lv粉色| 91亚洲导航深夜福利| 精品国产亚洲一区二区在线观看| 99久久99这里只有免费费精品| 国产精品永久免费| 亚洲av无码专区在线观看下载 | 亚洲精品乱码久久久久久中文字幕 | 亚洲一线产区二线产区精华| 亚洲AV伊人久久青青草原| 成人免费毛片内射美女-百度| 国产伦精品一区二区免费| 久久精品国产亚洲AV天海翼| 亚洲精品无码久久毛片波多野吉衣| 亚洲伊人成无码综合网| 日韩高清免费观看| 成视频年人黄网站免费视频| 日韩av无码免费播放| g0g0人体全免费高清大胆视频| 亚洲av成人中文无码专区| 亚洲狠狠成人综合网| 亚洲大香人伊一本线| 亚洲AV香蕉一区区二区三区|