实例3:返回数组
来源:互联网 发布:国际日期变更线的算法 编辑:程序博客网 时间:2024/05/19 09:13
Example3 (listCode() return String[]: all logincodes).
1. mysql: database(spring), testing table(spring) (same as Example1)
2. axisclasspath: ...... D:/mydemos/axis_text/src (same as Example1)
3. java codes for server: (D:/mydemos/axis_text/src/)
a) hibernate.cfg.xml (same as Example1)
b) Tblogin.hbm.xml (same as Example1)
c). LoginDaoImpl.java (should be put in the directory as: %webapp%/web-inf/classes/....)
package cn.com.mytest.dao;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import org.hibernate.Session;
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.hibernate.Query;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import cn.com.mytest.dao.hibernate.config.SessionFactoryClass;
public class LoginDaoImpl {
private static final Log log = LogFactory.getLog(LoginDaoImpl.class);
public void add(Serializable object){....(same as Example1)}
public List list(){....(same as Example1)}
public Object get(Integer loginid){ ... (same as example2)... }
}
4) LoginImpl.java (should be put in the directory of server side as: %webapp%/web-inf/classes/....)
package cn.com.mytest.server;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.mytest.dao.hibernate.Tblogin;
import cn.com.mytest.dao.LoginDaoImpl;
public class LoginImpl {
private static final Log log = LogFactory.getLog(LoginImpl.class);
LoginDaoImpl dao = new LoginDaoImpl();
public List list(){... same as Example1...}
public String[] listCodes(){
List list = dao.list();
if(list!=null){
String[] codes = new String[list.size()];
for(int i=0;i<list.size();i++){
Tblogin login = (Tblogin) list.get(i);
log.info("the login result: number " + i + ", loginname=" + login.getLogincode().trim().toUpperCase());
codes[i] = login.getLogincode().trim().toUpperCase();
}
return codes;
}else{
log.info("there is no rows in the table Tblogin");
return null;
}
}
}
4. wsdd file: deploy.wsdd (cn/com/mytest/server/deploy.wsdd)
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="LoginService" provider="java:RPC">
<parameter name="className" value="cn.com.mytest.server.LoginImpl"/>
<parameter name="allowedMethods" value="*"/>
<beanMapping qname="myNS:Tblogin" xmlns:myNS="urn:LoginImpl" languageSpecificType="java:cn.com.mytest.dao.hibernate.Tblogin"/>
</service>
</deployment>
wsdd file: undeploy.wsdd(cn/com/mytest/server/undeploy.wsdd) (same as Example10
5) Testing from client:
package cn.com.mytest.client;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class TestClient {
public static void main(String [] args)
{
try {
String endpointURL = "http://localhost:8080/axis/services/LoginService";
Service service = new Service();
Call call = (Call) service.createCall();
QName qn = new QName( "urn:LoginImpl", "Tblogin" );
call.registerTypeMapping(String[].class, qn,
new org.apache.axis.encoding.ser.ArraySerializerFactory(),
new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName( new QName("http://server.mytest.com.cn", "listCodes") );
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_ANYTYPE);
String[] names = (String[]) call.invoke(new Object[]{});
if(names!=null){
for(int i=0;i<names.length;i++){
String name = names[i];
System.out.println(name);
}
}
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
- 实例3:返回数组
- 实例4:返回对象数组
- C/C++ 分割字符并返回字符数组实例
- 6.3.3 返回数组指针
- c++primar 6.3.3 返回数组指针
- C#调用含有数组类形参和返回值的matlab函数实例
- Activity经典实例:启动其他Activity并使用Bundle存储数组返回结果
- Android—JNI调用简单实例解析/Eclipse无添加NDK的选项/JNI返回数组
- 实例1:返回INT
- 实例2:返回对象
- 过程返回游标实例
- js返回顶部实例
- 返回当前实例对象
- 返回数组中的最大值
- 利用showmodalDialog返回数组
- showModalDialog返回数组
- 如何返回局部数组?
- 关于数组返回
- centos64位,apache2,python2.5,django,mod_python平台安装配置。
- ubuntu白屏解决方法
- java程序员面试必备问答汇总
- 实例2:返回对象
- ubuntu 系统字体全部口口口口口口口口口口口口的解决办法
- 实例3:返回数组
- json对象转字符串形式
- 科技论文中的分析与综合-如何写好科技论文之我见(七)
- LINK错误总结1
- 暴雪公司字符串HASH函数
- 2009年招录老婆全国统一考试试卷
- 编程中遇到的数学问题
- sql大全超详细【转】
- 超级简单的大写金额转换--阿拉伯数字转中文大写