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

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

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

    朱杰兵blog

    jonhney'blog
    posts - 140, comments - 1, trackbacks - 0, articles - 0

    通過HttpClient請(qǐng)求webService 

    由于服務(wù)端是用webService開發(fā)的,android要調(diào)用webService服務(wù)獲取數(shù)據(jù),這里采用的是通過HttpClient發(fā)送post請(qǐng)求,獲取webService數(shù)據(jù)。
     
    服務(wù)端使用的webService框架是axis2,請(qǐng)求數(shù)據(jù)之前,要封裝一個(gè)xml格式,再通過post請(qǐng)求,獲取服務(wù)端數(shù)據(jù)。
    請(qǐng)求的xml格式如下所示: 
    1 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"xmlns:sam="http://user.service.xxx.com">
    2    <soap:Header/>
    3    <soap:Body>
    4       <sam:getUserInfo>
    5      <sam:userName>sunlightcs</sam:userName>
    6       </sam:getUserInfo>
    7    </soap:Body>
    8 </soap:Envelope>
    其中:getUserInfo是方法名,userName是參數(shù)名,當(dāng)然,還可以加多個(gè)參數(shù)。
     
     
    下面的代碼是向webService發(fā)送請(qǐng)求,獲取數(shù)據(jù),返回的數(shù)據(jù)是xml形式的,android只要解析xml數(shù)據(jù),就可以獲得想要的數(shù)據(jù)了。 

    01 import java.io.IOException;
    02 import java.io.OutputStream;
    03 import java.io.OutputStreamWriter;
    04 import java.io.Writer;
    05  
    06 import org.apache.http.HttpResponse;
    07 import org.apache.http.client.HttpClient;
    08 import org.apache.http.client.methods.HttpPost;
    09 import org.apache.http.entity.ContentProducer;
    10 import org.apache.http.entity.EntityTemplate;
    11 import org.apache.http.impl.client.DefaultHttpClient;
    12 import org.apache.http.util.EntityUtils;
    13  
    14  
    15 public class ClientTest {
    16  
    17     public static void main(String[] args) {
    18         ClientTest.httpClientPost();
    19     }
    20      
    21     private static void httpClientPost() {
    22         HttpClient client = new DefaultHttpClient();
    23         HttpPost post = newHttpPost("http://localhost:8080/xxx/services/userService");
    24          
    25         try {
    26             ContentProducer cp = new ContentProducer() {
    27                 public void writeTo(OutputStream outstream) throwsIOException {
    28                     Writer writer = new OutputStreamWriter(outstream,"UTF-8");
    29                      
    30                     /**
    31                      * 獲取請(qǐng)求的xml格式數(shù)據(jù)
    32                      */
    33                     String requestXml = getRequestXml();
    34                     writer.write(requestXml);
    35                     writer.flush();
    36                 }
    37             };
    38  
    39             post.setEntity(new EntityTemplate(cp));
    40             HttpResponse response = client.execute(post);
    41              
    42         //打印返回的xml數(shù)據(jù)
    43             System.out.println(EntityUtils.toString(response.getEntity()));
    44         catch (IOException e) {
    45             e.printStackTrace();
    46         }
    47     }
    48      
    49      
    50     private static String getRequestXml(){
    51         StringBuilder sb = new StringBuilder("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:sam=\"http://user.service.xxx.com\">");
    52         sb.append("<soap:Header/>");
    53         sb.append("<soap:Body>");
    54         sb.append("<sam:getUserInfo>");
    55         sb.append("<sam:userName>sunlightcs</sam:userName>");
    56         sb.append("</sam:getUserInfo>");
    57         sb.append("</soap:Body>");
    58         sb.append("</soap:Envelope>");
    59          
    60         return sb.toString();
    61     }
    62  
    63 }

    返回的數(shù)據(jù)格式如下: 
    1 <?xml version='1.0' encoding='UTF-8'?>
    2 <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
    3     <soapenv:Body>
    4         <ns:getUserInfoResponse xmlns:ns="http://user.service.xxx.com">
    5             <ns:return>xxx</ns:return>
    6         </ns:getUserInfoResponse>
    7     </soapenv:Body>
    8 </soapenv:Envelope>
    其中,<ns:return>內(nèi)的"xxx"可以是json數(shù)據(jù),android只需解析標(biāo)簽<ns:return>里的json數(shù)據(jù)即可。 
    轉(zhuǎn)載 http://www.juziku.com/wiki/3919.htm

    posted @ 2017-05-24 16:10 朱杰兵 閱讀(1222) | 評(píng)論 (0)編輯 收藏

    netstat -pan|grep 7001
    找到進(jìn)程號(hào),kill -9殺死
    打開啟動(dòng)路徑
    nohup ./startWeblogic.sh &
    tail -f nohup.out看啟動(dòng)日志
    ---------------------------
    csh   服務(wù)端運(yùn)行
    ps -ef | grep weblogic
    kiss -9 sid(左邊id)
    (
    查看后臺(tái)web進(jìn)程 
    #ps -ef|grep java 如: 
         root 123456 2346546 
        root 1346464    64646464 
    殺后臺(tái)進(jìn)程 :#kill -9 1346464 
    )
    cd 到。。。bin/startWebLogic.sh &    注意大小寫

    posted @ 2017-04-26 19:53 朱杰兵 閱讀(97) | 評(píng)論 (0)編輯 收藏

    java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory

    解決辦法

    刪掉war包中的xml-apis.jar就可以了

    posted @ 2017-04-14 16:06 朱杰兵 閱讀(106) | 評(píng)論 (0)編輯 收藏

    右鍵pom文件 run as --> maven build,  goals填入相應(yīng)命令,點(diǎn)run

    打包
    goals 輸入 clean package

    安裝jar到倉庫
    goals 輸入 clean install

    測(cè)試
    goals 輸入 clean test

    編譯
    goals 輸入 compile

    清除
    goals輸入 clean

     clean  清除編譯,compile  編譯,test  編譯并測(cè)試,install 打包并發(fā)送到本地倉庫,package 只是打成jar包,并不會(huì)發(fā)送到本地倉庫

    posted @ 2017-04-13 14:16 朱杰兵 閱讀(181) | 評(píng)論 (0)編輯 收藏

    posted @ 2017-04-12 17:50 朱杰兵 閱讀(2478) | 評(píng)論 (0)編輯 收藏

    public enum MessageLevel {
        LOW {
            @Override
            public String getDesc() {
                return "低";
                        
            }

            @Override
            public String getCode() {
                return "L";
            }

            @Override
            public String getIcon() {
                return "medal_bronze_1.png";
            }

        },
        HEIGH {

            @Override
            public String getDesc() {
                return "高";
            }

            @Override
            public String getCode() {
                return "H";
            }

            @Override
            public String getIcon() {
                return "medal_gold_1.png";
            }

        },
        NORMAL {

            @Override
            public String getDesc() {
                return "中";
            }

            @Override
            public String getCode() {
                return "N";
            }

            @Override
            public String getIcon() {
                return "medal_silver_1.png";
            }

        };
        
        public abstract String getDesc();

        public abstract String getCode();

        public abstract String getIcon();
    }

    1. public static void main(String[] args)  
    2.     {  
    3.         System.out.println(MessageLevel.LOW.getDesc());  
    4.         System.out.println(MessageLevel.LOW.getCode());
    5.         System.out.println(MessageLevel.LOW.getIcon());
    6.     } 
    -----------------------------------------------------------------------------------------------
    1. public enum Operation   
    2. {  
    3.     PLUS  
    4.     {  
    5.         public double eval(double x,double y)  
    6.         {  
    7.             return x+y;  
    8.         }  
    9.     },  
    10.     MINUS  
    11.     {  
    12.         public double eval(double x,double y)  
    13.         {  
    14.             return x-y;  
    15.         }  
    16.     },  
    17.     TIMES  
    18.     {  
    19.         public double eval(double x,double y)  
    20.         {  
    21.             return x*y;  
    22.         }  
    23.     },  
    24.     DIVIDE  
    25.     {  
    26.         public double eval(double x,double y)  
    27.         {  
    28.             return x/y;  
    29.         }  
    30.     };  
    31.     //為枚舉類定義一個(gè)抽象方法,這個(gè)抽象方法由不同的枚舉值提供不同的實(shí)現(xiàn)。  
    32.     public abstract double eval(double x,double y);  
    33.     public static void main(String[] args)  
    34.     {  
    35.         System.out.println(Operation.PLUS.eval(3,4));  
    36.         System.out.println(Operation.MINUS.eval(5,4));  
    37.         System.out.println(Operation.TIMES.eval(5,4));  
    38.         System.out.println(Operation.DIVIDE.eval(5,4));  
    39.     }  

    posted @ 2017-04-07 11:19 朱杰兵 閱讀(94) | 評(píng)論 (0)編輯 收藏

    classpath

    首先 classpath是指編譯過后的WEB-INF文件夾下的的classes目錄

    • 對(duì)于maven的所有項(xiàng)目, 配置文件一般放在resources目錄下, 當(dāng)編譯之后會(huì)自動(dòng)復(fù)制到classes目錄下
    • 非maven的所有項(xiàng)目, 一般放在src目錄下, 編譯之后也會(huì)自動(dòng)復(fù)制到classes目錄下面.
    • 所有的web-app項(xiàng)目, 例如web.xml, spring的配置文件等等,是放在webapp/WEB-INF下面的,
      如果想要引用resources或者src目錄下的配置文件, 就在在配置文件的路徑前加上classpath:, 例如MyBatis配置文件的引用.
      <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  <property name="dataSource" ref="dataSource"/>  <property name="configLocation" value="classpath:MybatisConfiguration.xml"/>  <property name="mapperLocations" value="classpath*:com/tenlee/mapper/UserMapper.xml"/> </bean>
    • 如果不加的的話,那么都要把配置文件放在WEB-INF/目錄下面, 但這樣不能單獨(dú)運(yùn)行java類進(jìn)行調(diào)試了,必須要啟動(dòng)整個(gè)webapp, 比如這樣
      <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/configs/mvc-dispatcher.xml</param-value> </init-param>

    classpath classpath* 區(qū)別:

    • classpath:只會(huì)到你的classes路徑中查找找文件
    • classpath* :不僅包含classes路徑,還包括jar文件classes路徑進(jìn)行查找
    • classpath:classpath*:的區(qū)別在于,前者只會(huì)從第一個(gè)classpath中加載,而后者會(huì)從所有的classpath中加載 如果要加載的資源,不在當(dāng)前ClassLoader的路徑里,那么用classpath:前綴是找不到的,這種情況下就需要使用classpath*:前綴.
    • 另一種情況下,在多個(gè)classpath中存在同名資源,都需要加載,那么用classpath:只會(huì)加載第一個(gè),這種情況下也需要用classpath*:前綴.
    • 可想而知,用classpath*:需要遍歷所有的classpath,所以加載速度是很慢的,因此,在規(guī)劃的時(shí)候,應(yīng)該盡可能規(guī)劃好資源文件所在的路徑,盡量避免使用classpath*

    posted @ 2017-04-06 14:32 朱杰兵 閱讀(187) | 評(píng)論 (0)編輯 收藏

         摘要: 如果你經(jīng)常需要在Eclipse里打開相關(guān)資源文件所在的文件夾,比較麻煩,要右鍵,屬性,在Location一欄中把所在的文件夾拷貝一下,然后再去資源管理器里輸入這個(gè)路徑,回車,然后打開它,比較麻煩。下載地址:http://download.csdn.net/download/lang791534167/8585091eclipse3.6以下的版本將下載的jar包復(fù)制到plugins目錄下3.6以上包...  閱讀全文

    posted @ 2017-04-05 09:32 朱杰兵 閱讀(113) | 評(píng)論 (0)編輯 收藏

         摘要: 解決方法: 步驟一: 從http://maven.oschina.net/content/groups/public/org/apache/maven/archetypes/maven-archetype-quickstart/ 下載最新版maven-archetype-quickstart-1.1.jar 步驟二: 命令行到下載目錄下執(zhí)行 mvn install...  閱讀全文

    posted @ 2017-03-31 11:13 朱杰兵 閱讀(2221) | 評(píng)論 (0)編輯 收藏

    properties文件默認(rèn)應(yīng)該顯示為unicode編碼,如果安裝propertiesEditor插件后可顯示為中文

    如果沒有安裝插件,但顯示中文,則程序調(diào)用屬性文件會(huì)出現(xiàn)亂碼問題,這樣就需要手動(dòng)來將中文轉(zhuǎn)為unicode

    直接使用JDK自帶的工具:native2ascii.exe

    運(yùn)行cmd,直接用命令的形式,找到文件對(duì)應(yīng)的目錄,輸入以下命令,

    命令格式:native2ascii -encoding UTF-8 源文件名.properties 目標(biāo)文件名.properties

    就可以將含有中文的源文件轉(zhuǎn)為unicode編碼的目標(biāo)文件

    posted @ 2017-03-29 14:11 朱杰兵 閱讀(126) | 評(píng)論 (0)編輯 收藏

    僅列出標(biāo)題
    共14頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
    主站蜘蛛池模板: 亚洲永久精品ww47| 看免费毛片天天看| 国产AⅤ无码专区亚洲AV| 希望影院高清免费观看视频 | 久久久久久精品成人免费图片| 美女视频黄a视频全免费网站一区 美女视频黄a视频全免费网站色 | 日本xxwwxxww在线视频免费| 日韩在线永久免费播放| www免费黄色网| 18禁亚洲深夜福利人口| 国产婷婷综合丁香亚洲欧洲| 亚洲AV成人片色在线观看高潮| 亚洲天堂中文字幕在线| 日本特黄特色免费大片| 99无码人妻一区二区三区免费| 午夜爽爽爽男女免费观看影院| 色老头综合免费视频| 国产精品亚洲va在线观看| 亚洲国产区男人本色在线观看| 自怕偷自怕亚洲精品| 婷婷亚洲综合五月天小说| 国产亚洲成人在线播放va| 亚洲高清免费视频| 四虎永久在线精品免费观看地址 | 亚洲视频日韩视频| 亚洲精品高清国产一久久| 亚洲国产AV无码专区亚洲AV| 亚洲午夜久久久影院| 久久99亚洲综合精品首页| 亚洲人成无码网WWW| 亚洲精品成人在线| 亚洲国产精品碰碰| 国产L精品国产亚洲区久久| 亚洲人成无码久久电影网站| 亚洲国产成人久久综合碰| 亚洲Av无码国产情品久久| 免费国产成人高清视频网站| 全亚洲最新黄色特级网站| 91在线亚洲精品专区| 亚洲AV综合色一区二区三区| 国产精品亚洲A∨天堂不卡 |