JAVA WebService实例
一、Axis安装 1、环境 J2SE SDK 1.5 or 1.6: 我使用 1.6 Servlet Container: 我使用的Tomcat 6.0
2、到 http://ws.apache.org/Axis/网站下载Axis安装包
3、先在eclipse下新建web project为WebServiceDemo.在Tomcat的配置xml配置上:<Context path="/webservice" docBase="D:\workspace\WebServiceDemo\WebRoot"/>.解压下载的axis安装包,将webapps\axis下的lib文件夹和web.xml文件拷到工程对应目录
4、启动tomcat,访问http://localhost/webservice检查安装是否成功,我的端口设置为80,页面index.html自动跳转后出错,是因为没把类拷入,先不管。
5、以上步骤执行成功,可以开发webservice例子了
Axis支持三种web service的部署和开发,分别为:
1、Dynamic Invocation Interface ( DII)
2、Stubs方式
3、Dynamic Proxy方式
二、编写DII(Dynamic Invocation Interface )方式web服务
1.新建包com.qdl.server,编写服务端程序SayHello
package com.qdl.server;
public class SayHello
{
public String getName(String name)
{
return "hello "+name;
}
}
2、将源码拷贝到WebRoot下,重命名为 SayHello.jws (注意不用拷上面的package ...行)
3、访问连接http://localhost/webservice/SayHello.jws?wsdl,页面显示Axis自动生成的wsdl,同时会在WEB-INF下创建jwsClasses文件夹,在此生成SayHello.class文件
4、新建包com.qdl.client,编写访问服务的客户端 SayHelloClient.java
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class SayHelloClient {
public static void main(String[] args){
//程序访问即时发布的服务
try{
//创建访问点
String endpoint = "http://localhost/webservice/SayHello.jws";
//创建service
Service service = new Service();
Call call = null;
//创建call
call = (Call) service.createCall();
//设置操作名
call.setOperationName(new QName("http://localhost/webservice/SayHello.jws","getName"));
//设置访问点
call.setTargetEndpointAddress(new java.net.URL(endpoint));
//调用服务,返回值
String ret = (String) call.invoke(new Object[]{"zhangsan"});
System.out.println("返回的
相关文档:
1.散列集HashSet
HashSet类在java.util包中
A.构造方法:HashSet()
B.常用方法
public boolean add(Object o):向集合中添加指定元素o
&nb ......
需要dom4j.jar文件 ,自行下载。 test.xml 1: <?xml version="1.0" encoding="gbk"?>
2:
3: <students>
4: <person sex="男" age="21">
5: <id>1</id>
6: <name>章治鹏</name>
7: <homepage&g ......
当Java程序创建一个类的实例或者数组时,都在堆中为新的对象分配内存。虚拟机中只有一个堆,所有的线程都共享它。
1、垃圾收集(Garbage Collection)
垃圾收集是释放没有被引用的对象的主要方法。它也可能会为了减少堆的碎片,而移动对象。 ......
使用类java.io.File
1.获取系统硬盘信息:
public static String getDiskInfo() {
StringBuffer sb=new StringBuffer();
File[] roots = File.listRoots();// 获取磁盘分区列表
for (File file : roots) {
long totalSpace=file.getTotalSpace();
long freeSpace=file.getFreeSpace();
long usa ......
Object Ordering
A List l may be sorted as follows.
Collections.sort(l);
If the List consists of String elements, it will be sorted into alphabetical order. If it consists of Date elements, it will be sorted into chronological order. How does this happen? String and Date both implement the Compara ......