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

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

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

    隨筆 - 119  文章 - 3173  trackbacks - 0
    <2015年10月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    交友莫獨酒,茅臺西鳳游。
    口干古井貢,心徜洋河流。
    稱多情杜康,趟無量雙溝。
    贊中華巍巍,無此不銷愁。

    常用鏈接

    留言簿(68)

    隨筆分類(136)

    隨筆檔案(122)

    最新隨筆

    搜索

    •  

    積分與排名

    • 積分 - 525023
    • 排名 - 93

    最新評論

    為了滿足廣大網友的要求,今天抽時間搞了下WebServices 在tomcat中的發布
    相關文章:
    tomcat啟動時自動加載servlet
    學習Java6(一) WebServices (1)服務端
    學習Java6(一) WebServices (2)客戶端

    新建一個servlet,偶太,能少打一個字符都是好的,所以servlet寫的非常簡潔,也適合初學者看得懂。。。。。。。。。。
    WebServiceStarter.java

    ?1?import?javax.servlet.ServletException;
    ?2?import?javax.servlet.http.HttpServlet;
    ?3?import?javax.xml.ws.Endpoint;
    ?4?
    ?5?public?class?WebServiceStarter?extends?HttpServlet?{
    ?6?????
    ?7?????private?static?final?long?serialVersionUID?=?5870534239093709659L;
    ?8?
    ?9?????public?WebServiceStarter()?{
    10?????????super();
    11?????}
    12?
    13?????public?void?destroy()?{
    14?????????super.destroy();
    15?????}
    16?
    17?????public?void?init()?throws?ServletException?{
    18?????????System.out.println("準備啟動服務");
    19?????????Endpoint.publish("http://localhost:8080/HelloService",?new?Hello());
    20?????????System.out.println("服務啟動完畢");
    21?????}
    22?}
    23?

    web service類Hello.java也是非常簡單
    ?1?
    ?2?
    ?3?import?javax.jws.WebMethod;
    ?4?import?javax.jws.WebService;
    ?5?import?javax.jws.soap.SOAPBinding;
    ?6?
    ?7?@WebService(targetNamespace?=?"http://jdk.study.hermit.org/client")
    ?8?@SOAPBinding(style?=?SOAPBinding.Style.RPC)
    ?9?public?class?Hello?{
    10?????@WebMethod
    11?????public?String?sayHello(String?name)?{
    12?????????return?"hello:"?+?name;
    13?????}
    14?}
    web.xml
    ?1?<?xml?version="1.0"?encoding="UTF-8"?>
    ?2?<web-app?version="2.4"?xmlns="http://java.sun.com/xml/ns/j2ee"
    ?3?????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    ?4?????xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee?
    ?5?????http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    ?6?????<servlet>
    ?7?????????<servlet-name>WebServiceStarter</servlet-name>
    ?8?????????<servlet-class>WebServiceStarter</servlet-class>
    ?9?????????<load-on-startup>1</load-on-startup>
    10?????</servlet>
    11?</web-app>
    12?

    ok
    就這三個文件。。。。。。。。。啥jar都不要。。。。
    發布,啟動服務器
    2007-1-5 13:28:37 org.apache.catalina.core.AprLifecycleListener init
    信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: G:\JDK6\bin;F:\tomcat6\bin
    2007-1-5 13:28:37 org.apache.coyote.http11.Http11Protocol init
    信息: Initializing Coyote HTTP/1.1 on http-8080
    2007-1-5 13:28:37 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 937 ms
    2007-1-5 13:28:38 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2007-1-5 13:28:38 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/6.0.7
    2007-1-5 13:28:38 org.apache.catalina.core.StandardHost start
    信息: XML validation disabled
    2007-1-5 13:28:38 org.apache.catalina.core.ApplicationContext log
    信息: ContextListener: contextInitialized()
    2007-1-5 13:28:38 org.apache.catalina.core.ApplicationContext log
    信息: SessionListener: contextInitialized()
    準備啟動服務
    服務啟動完畢
    2007-1-5 13:28:39 org.apache.coyote.http11.Http11Protocol start
    信息: Starting Coyote HTTP/1.1 on http-8080
    2007-1-5 13:28:39 org.apache.jk.common.ChannelSocket init
    信息: JK: ajp13 listening on /0.0.0.0:8009
    2007-1-5 13:28:39 org.apache.jk.server.JkMain start
    信息: Jk running ID=0 time=16/62? config=null
    2007-1-5 13:28:39 org.apache.catalina.startup.Catalina start
    信息: Server startup in 1969 ms


    訪問:http://localhost:8080/HelloService?wsdl
    ?1???<?xml?version="1.0"?encoding="UTF-8"??>?
    ?2?-?<definitions?xmlns="http://schemas.xmlsoap.org/wsdl/"?xmlns:tns="http://jdk.study.hermit.org/client"?xmlns:xsd="http://www.w3.org/2001/XMLSchema"?xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"?targetNamespace="http://jdk.study.hermit.org/client"?name="HelloService">
    ?3???<types?/>?
    ?4?-?<message?name="sayHello">
    ?5???<part?name="arg0"?type="xsd:string"?/>?
    ?6???</message>
    ?7?-?<message?name="sayHelloResponse">
    ?8???<part?name="return"?type="xsd:string"?/>?
    ?9???</message>
    10?-?<portType?name="Hello">
    11?-?<operation?name="sayHello"?parameterOrder="arg0">
    12???<input?message="tns:sayHello"?/>?
    13???<output?message="tns:sayHelloResponse"?/>?
    14???</operation>
    15???</portType>
    16?-?<binding?name="HelloPortBinding"?type="tns:Hello">
    17???<soap:binding?style="rpc"?transport="http://schemas.xmlsoap.org/soap/http"?/>?
    18?-?<operation?name="sayHello">
    19???<soap:operation?soapAction=""?/>?
    20?-?<input>
    21???<soap:body?use="literal"?namespace="http://jdk.study.hermit.org/client"?/>?
    22???</input>
    23?-?<output>
    24???<soap:body?use="literal"?namespace="http://jdk.study.hermit.org/client"?/>?
    25???</output>
    26???</operation>
    27???</binding>
    28?-?<service?name="HelloService">
    29?-?<port?name="HelloPort"?binding="tns:HelloPortBinding">
    30???<soap:address?location="http://localhost:8080/HelloService"?/>?
    31???</port>
    32???</service>
    33???</definitions>
    看到以上代碼就ok!
    客戶端寫法照舊

    呵呵,這下大家滿意了吧。。。。。。。。。
    有沖動想把項目里的xfire撤掉了。。。。。。。。。。。。。。。。。
    posted on 2007-01-05 13:38 交口稱贊 閱讀(12541) 評論(40)  編輯  收藏 所屬分類: Java6J2EE & WEB

    FeedBack:
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-01-05 13:41 交口稱贊
    忘了說環境

    eclipse3.2.1+myeclipse5.1
    jdk6
    tomcat6.0.7

    出現問題請先檢查下自己的環境。

    如果你在其它環境下也能通過謝謝你告訴我  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-01-05 13:43 交口稱贊
    剛才測試了
    jboss4.0.5也沒問題

    看來基本上可以通用  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-01-07 13:57 冷面閻羅
    不過我感覺還是不實用,因為現在jdk6在項目中基本上是不能被用到,目前大多數還是用的jdk4.所以這樣的 只能是我們玩玩而已.用到實際開發估計還要一段時間  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-01-07 18:53 交口稱贊
    呵呵
    在新項目里面可以直接用哦
    我們項目現在就用到了JDK5的很多新特性

    而且很多開源的東西都用的很多新東西

    感覺用起來比xfire還爽  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-01-07 18:54 交口稱贊
    有空來測試下性能。。。。。。。。。

    看看哪個牛

    誰有LoadRunner8.1的License啊  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-01-07 23:36 正需要啊
    z終于盼到了  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-01-08 22:45 東方游

      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-01-11 16:55 jht
    nod
    我去SUN JAVA網站上也找了幾篇文章,挺好的,大家可以自己去找找  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-16 21:11 sdf
    can you tell me, how can i create a servlet in eclipse and how can i publish this WS? in very detail!!

    Thanks a lot!  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-16 21:13 sdf
    can i develop this WS without Xfire?  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-16 21:34 交口稱贊
    1.服務端程序:我要怎樣在eclipse里寫"servlet"和"web service"兩個java程序?
    新建一個web項目
    新建servlet
    新建java類
    內容按照上面的例子  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-16 21:37 交口稱贊
    2.我怎樣執行他們,才能把他們發布出去?

    一般項目在eclipse都是自動編譯的
    我是用的myeclipse
    可以直接部署到tomcat或者jboss,有個小按鈕,點了以后是向導式的,你一步一步做,看你英文這么好,應該搞的定
    這個就是IDE的基本使用

    啟動tomcat就算發布出去了
    測試是否發布成功,本文已經寫了  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-16 21:40 交口稱贊
    您能否在說說分別用java6開發WS和用axis2開發ws的優缺點

    axis2沒用過,不敢說,但是印象不好

    java6的WS經過我的這幾篇文章探索,個人還有很多問題沒解決,感覺還是不要用在項目里面的好,畢竟現在很多項目還是在jdk1.4或者1.5

    你要是項目里面需要用webservice推薦你使用xfire

      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-16 21:41 交口稱贊
    can i develop this WS without Xfire?

    你直接用java6的webservice可以不用XFIRE  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布[未登錄] 2007-04-23 16:26 daisy
    不知道在NetBeans里可以嗎?直接在一個Web項目里依次建好上面幾個文件,然后啟動Tomca就可以嗎?  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-23 16:58 交口稱贊
    樓上抱歉
    沒在NB下面試過

    理論上應該可以

    還是建議你用eclipse吧
    為你以后工作好  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布[未登錄] 2007-04-24 16:02 daisy
    為什么我用NB寫的WS(JDK1.6)放在這里說:syntax error,annotations are only
    available if source level is 5.0?
    然后我在你要求的環境下寫的代碼,和你的格式一樣.仍然在@WebService @SOAPBinding @WebMethod下面有紅色波浪線,并報告上述錯誤?
    直接建一個calss文件,編寫WS,可以嗎?  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-24 16:05 交口稱贊
    可以,你是不是裝的jdk6?
      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布[未登錄] 2007-04-24 16:12 daisy
    因為我是急著完成需要的功能,所以并沒有時間去多看基礎的東西.本來對eclipse不熟悉.
    所以問的問題可能顯得有些白癡,不過請你陳情幫忙看看,謝謝了!

    我現在JDK1.5 1.6 都有了!我以為是JDK版本的問題,換成1.5的也不行
      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布[未登錄] 2007-04-24 16:14 daisy
    可以加你的QQ,或者MSN嗎?萬分感謝!  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布[未登錄] 2007-04-24 16:15 daisy
    如果你不想公開,我告訴你我的吧!謝謝了!
    QQ:315768093  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-24 16:22 交口稱贊
    你項目中還是別用這個了

    用xfire吧

    你弄個jdk6
    估計你們頭是不會為了你的功能改項目JDK的

      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-26 17:32 HEDY
    Netbeans中開發Webservice更容易  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-26 19:26 sdf
    Thank you for your reply. i cann't write chinese on my computer, sorry:(

    so, must "WebServiceStarter.java" be a "servlet"? and must i create a Web-Project?

    I have a WS with axis1.x, now i wanne to change its library only with java6. for example, i hve to authenticate the user with "BasicHandler.invoke()", but it only belones to axis, what should i do, if i write this function in java6? which one can be instead it? and so on... the things like this are so many, that makes me headache.

    That' my pleasure, if i could talk with you in msn
    i'm iceapplexin@hotmail.com

    Thank you  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-04-30 21:16 sdf
    It doesn't work!!!
    By the compiling WebServiceStarter.java:
    1 error
    WebServiceStarter.java:19: cannot find symbol
    symbol : class Hello
    location: class WebServiceStarter
    Endpoint.publish("http://localhost:8080/HelloService", new Hello());


    Tell me Why,please!!!   回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-05-01 00:34 交口稱贊
    。。。。
    樓上
    我會放一個myeclipse項目,到時候你直接導入就可以了。。。。。


    或者建個eclipse的web項目。。。。

    你要那種?  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-05-01 03:43 sdf
    "eclipse的web項目" is better for me,

    but even better, if you do it with "Tomcat Project" and without MyEclipse (I mean only Eclipse alone, without the "deploy"-Button, how would you do the deployment step by step per hand?
    Is this so right?: Deployment = copy all *.class files in the dictionary WEB-INF/classes?).

    Thanks a lot!  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-05-01 07:11 交口稱贊
    不用myeclipse沒問題。。
    你有WTP嗎?
    Web Tools Platform
    http://download.eclipse.org/eclipse/downloads/

    有這個做WEB開發也可以  回復  更多評論
      
    # Developing Java6 WS with TomcatProject in Eclipse 2007-05-03 19:03 sdf
    Oh, yes. I have done it!!
    I will write it here for you as Thanks and for you all.

    Step by step
    0> first you must have Tomcat-plugin in your eclipse

    1>. Server-side-programm

    1. File->new->other->java->
    create a Tomcat-Project named "TomWs"->finish

    2. in WEB-INF\src create

    HelloServlet.java: a Servlet, the only duty is to publish the WS-endpoint onto a URL (hier is Http://localhost:8080/services)

    import java.io.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    import javax.swing.JOptionPane;
    import javax.xml.ws.Endpoint;


    public class HelloServlet extends HttpServlet {
    public void doGet (HttpServletRequest req,
    HttpServletResponse res)
    throws ServletException, IOException
    {
    Endpoint endpoint = Endpoint.publish( "http://localhost:8080/services",
    new sayHello() );
    res.setContentType( "text/html" );
    PrintWriter out = res.getWriter();
    out.println( "<html>" );
    out.println( "Hallo, mein erstes Servlet meldet sich." );
    out.println( "</html>" );
    out.close();
    JOptionPane.showMessageDialog( null, "Server beenden" );
    endpoint.stop();

    }
    }
    SayHello.java: a normal class, describes the Web-Service with Jax-Ws Annotation.

    import javax.jws.soap.SOAPBinding;
    import javax.jws.*;

    @WebService(name="XinServ",targetNamespace="http:///")
    @SOAPBinding(style = SOAPBinding.Style.RPC)
    public class sayHello
    {
    @WebMethod
    public String hello( String name )
    {
    return "Hello " + name + "!";
    }

    @WebMethod(operationName="body-mass-index")
    @WebResult(name = "your-bmi")
    public double bmi( @WebParam(name="height") double height,
    @WebParam(name="weight") double weight )
    {
    return weight / (height * height) / 100 * 100;
    }
    }

    3. compile the tow classes in Web-Inf\classes with the two commandos:

    set classpath=C:\Tomcat\jakarta-tomcat-5.5.9\common\lib\servlet-api.jar
    javac -d classes -sourcepath src src\HelloServlet.java

    4. create web.xml in WEB-INF\web.xml
    <!DOCTYPE web-app PUBLIC
    '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
    '<web-app>
    <servlet>
    <servlet-name>hello</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>/hello</url-pattern>
    </servlet-mapping>
    </web-app>

    5. start Tomcat-server in eclipse
    Repeat to compile the classes = reload them in Tomcat
    6. in URL-Address input:
    http://localhost:8080/TomWs/hello, It’s the address of the Servlet, that only tomcat automatic loads. In the browser will show “Hello….”, and there are small dialog "server beenden", don’t close it, then go on with input the
    http://localhost:8080/services?wsdl. Wenn you can see this, you’re done!
    7. leave the little widow open.
      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-05-03 19:05 sdf

    Go on with the
    2>. Client-side-programm

    1. create a another java-project

    2. create a “wsimport.bat” file in the project-folder with

    wsimport -keep -p com http://localhost:8080/services?wsdl

    3. run the wsimport.bat, there will tow class automatic producted.

    4. create a class named “HelloClient.java”
    package com;
    public class ClientHello {
    public static void main( String[] args )
    {

    XinServ port = new SayHelloService().getXinServPort();
    System.out.printf( "%s Your BMI is %.1f%n",
    port.hello( "Xin" ),
    port.bodyMassIndex( 183, 84 ) );
    }
    }

    5. compile this and run it as java application in eclipse.

    6. if you cann't see anny eerors, than congratulations!
      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-05-04 15:52 高手
    樓上的好佩服你啊  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-05-04 17:13 sdf
    But This way is uncommon to write a WS, do you think, that develop WS with Java6+Tomcat is better and easier then with axis2? I don't know :(
    can anyone give some idears to me about that?  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-05-30 11:02 agoo
    準備啟動服務
    2007-5-30 10:55:04 org.apache.catalina.core.ApplicationContext log
    嚴重: StandardWrapper.Throwable
    java.lang.NoClassDefFoundError: javax/xml/ws/Endpoint
    運行以上程序出現的錯誤,
    環境是JRE1.6
    tomcat5.5  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-05-30 12:25 交口稱贊
    JRE1.6
    還是JDK?
      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布[未登錄] 2007-06-13 14:59 edward
    報以下錯誤,誤人子弟
    java.net.BindException: Address already in use: bind  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-06-14 09:23 交口稱贊
    Address already in use: bind

    你自己找個金山詞霸翻譯一下吧
      回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2007-06-21 09:17 楊一
    我有一個疑問:
    Web Service是怎樣自動部署到Tomcat中的?
    您這樣做僅僅是在JVM自帶的服務器中發布了WS,而Tomcat也僅僅起到了觸發JVM自帶服務器的作用,我想知道怎樣把WSDL部署到Tomcat里面,完全由這個成熟的Web服務器托管,或者您告訴我,現在已經做到這一點了  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2008-11-06 10:37 jeekchen
    這種方式只能單線程訪問的,沒實際用處  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2015-10-09 12:30 你二大爺
    Address already in use: bind
    暈死;;;  回復  更多評論
      
    # re: 學習Java6(一) WebServices (3)在tomcat中發布 2015-11-10 17:58 setyg
    靠,,這就叫發布到tomcat了,,忽悠誰呢。、  回復  更多評論
      
    主站蜘蛛池模板: 亚洲AV无码乱码国产麻豆| 成全视频高清免费观看电视剧| 亚洲VA成无码人在线观看天堂| 最近免费中文字幕大全| 免费黄网站在线观看| 午夜免费国产体验区免费的| 亚洲人成www在线播放| 亚洲国产精品第一区二区| 伊人久久大香线蕉亚洲五月天| 国产精品自在自线免费观看| 国产日本一线在线观看免费| 久久狠狠躁免费观看2020| 中文字幕av免费专区| 极品美女一级毛片免费| 亚洲av日韩精品久久久久久a| 亚洲av永久综合在线观看尤物| 亚洲卡一卡2卡三卡4卡无卡三| 亚洲色大成网站WWW久久九九| 亚洲精品无码成人片在线观看 | 亚洲国产综合精品一区在线播放| 女人张开腿给人桶免费视频| 成人浮力影院免费看| 蜜桃成人无码区免费视频网站| 国产免费爽爽视频在线观看| 久久www免费人成精品香蕉| 免费无码一区二区| 国产精品亚洲综合| 国产亚洲视频在线观看网址| 亚洲乱妇老熟女爽到高潮的片| 亚洲天堂免费在线| 亚洲综合色婷婷在线观看| 日韩亚洲不卡在线视频中文字幕在线观看 | 最近2019中文免费字幕| 一个人免费观看在线视频www| 国内精品免费麻豆网站91麻豆| xxxx日本免费| 欧美日韩国产免费一区二区三区| 成年性生交大片免费看| 成人人免费夜夜视频观看| 国产精品久免费的黄网站| 亚洲国产黄在线观看|