<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請求webService 

    由于服務(wù)端是用webService開發(fā)的,android要調(diào)用webService服務(wù)獲取數(shù)據(jù),這里采用的是通過HttpClient發(fā)送post請求,獲取webService數(shù)據(jù)。
     
    服務(wù)端使用的webService框架是axis2,請求數(shù)據(jù)之前,要封裝一個xml格式,再通過post請求,獲取服務(wù)端數(shù)據(jù)。
    請求的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)然,還可以加多個參數(shù)。
     
     
    下面的代碼是向webService發(fā)送請求,獲取數(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                      * 獲取請求的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 朱杰兵 閱讀(1214) | 評論 (0)編輯 收藏

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

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

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

    解決辦法

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

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

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

    打包
    goals 輸入 clean package

    安裝jar到倉庫
    goals 輸入 clean install

    測試
    goals 輸入 clean test

    編譯
    goals 輸入 compile

    清除
    goals輸入 clean

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

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

    posted @ 2017-04-12 17:50 朱杰兵 閱讀(2475) | 評論 (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.     //為枚舉類定義一個抽象方法,這個抽象方法由不同的枚舉值提供不同的實現(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 朱杰兵 閱讀(90) | 評論 (0)編輯 收藏

    classpath

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

    • 對于maven的所有項目, 配置文件一般放在resources目錄下, 當(dāng)編譯之后會自動復(fù)制到classes目錄下
    • 非maven的所有項目, 一般放在src目錄下, 編譯之后也會自動復(fù)制到classes目錄下面.
    • 所有的web-app項目, 例如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)試了,必須要啟動整個webapp, 比如這樣
      <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/configs/mvc-dispatcher.xml</param-value> </init-param>

    classpath classpath* 區(qū)別:

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

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

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

    posted @ 2017-04-05 09:32 朱杰兵 閱讀(113) | 評論 (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 朱杰兵 閱讀(2217) | 評論 (0)編輯 收藏

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

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

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

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

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

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

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

    僅列出標(biāo)題
    共14頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
    主站蜘蛛池模板: 最近2019免费中文字幕6| 色多多A级毛片免费看| 免费国产黄网站在线观看视频| 亚洲一区二区三区无码影院| 美女视频黄.免费网址 | 羞羞网站在线免费观看| 免费无码又爽又刺激高潮| 亚洲精品精华液一区二区| 国产又大又长又粗又硬的免费视频| 在线aⅴ亚洲中文字幕| 看全色黄大色大片免费久久| 国产成人高清亚洲一区久久| 亚洲精品无码久久毛片| 999zyz**站免费毛片| 麻豆亚洲AV永久无码精品久久| 最近中文字幕无免费| 亚洲欧美日韩自偷自拍| 国产a不卡片精品免费观看| 乱人伦中文视频在线观看免费| 亚洲日韩精品A∨片无码| 97公开免费视频| 亚洲国产欧美国产综合一区| 亚洲精品乱码久久久久久不卡| 日本免费高清视频| 亚洲精品亚洲人成在线播放| 又色又污又黄无遮挡的免费视 | 特级做a爰片毛片免费看| 亚洲AV永久精品爱情岛论坛| 美女内射毛片在线看免费人动物 | 亚洲日韩在线观看| 日韩电影免费在线观看| 日韩亚洲国产综合高清| 免费乱理伦在线播放| a级日本高清免费看| 亚洲AV男人的天堂在线观看| 亚洲伊人久久综合中文成人网| 99re免费在线视频| 国产偷国产偷亚洲高清人| 久久综合九九亚洲一区| 在线免费观看视频你懂的| 国产成人免费ā片在线观看老同学|