Web Services入门
来源:互联网 发布:电视上安装网络机顶盒 编辑:程序博客网 时间:2024/05/24 05:31
- Web services包括服务端和客户端。
- web services的描述语言为基于xml的 WSDL。
- UDDI 通用描述,发现及整合。
- SOAP简易对象访问协议。
- web services 可以把应用程序组件作为服务来提供 比如:天气预报;火车票售信息;语言翻译。
给大家操作一下简单的代码 如何去数据库提取数据然后发布到web上:
- 先创建服务端
第一步:先导架包fastjion 跟mysql的,我这里用到的版本是1.2.8 跟5.0.5的(要加载一下 build path),因为解析json和调用mysql数据库的时候要用
第二步:创建以下几个包;我就详细写一下util,ws,及test测试类的内容
因为连接mysql的dbhelp类我也有些生疏,所以就当练练手
1.加载驱动
static {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
2.得到连接
public static Connection getcon(){
Connection con=null;
try {con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","xxxx","xxxx");
System.out.println(con+":con");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
3.关闭资源
public static void close(Connection con,PreparedStatement ps,ResultSet rs){
try {
if(rs!=null) rs.close();
if(ps!=null) ps.close();
if(con!=null && !con.isClosed()) con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void close(Connection con, PreparedStatement ps){
close(con,ps,null);
}
try {
if(rs!=null) rs.close();
if(ps!=null) ps.close();
if(con!=null && !con.isClosed()) con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void close(Connection con, PreparedStatement ps){
close(con,ps,null);
}
---------------------------------------------------------------------------------------------------------------------
----接下来就是ws包
这里主要是创建一个接口类,然后实现接口,调用dao方法
-----------------------------上面是接口 ,下面是实现类
-------------------------------------------------------------------------------------------------------------------------------
-----------------------接下来是测试类
- 然后发布到web,先找到你的launch the web services Explorer ,这个得在java EE里才有,所以如果你的没有的话,就看看你的是否为java EE
第二步:把测试类里的地址填进去在后方加?WSDL然后点击Go,对了,你的地址必须为你电脑连接的Ip地址哦!
其他的就简单了。。。。。。。。
-----------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------客户端
阅读全文
0 0
- web Services入门实例
- SharePoint Web Services入门
- web services入门示例
- Web Services 入门
- SharePoint Web Services入门
- SharePoint Web Services入门
- Web Services 入门概念
- Web services快速入门
- Web Services入门
- VS.NET中Web Services入门
- vs.net中web services入门
- XFire开发Web Services入门例子
- Amazon Web Services的一些入门知识
- JAVA RESTful Web Services - Jersey 入门
- Web Services
- Web Services
- Web Services
- web services
- Java三大器之监听器(Listener)详解
- 数字电路的学习总结
- 指针数组与数组指针
- bzoj1455 罗马游戏【并查集+可并堆】
- Spring Boot核心条件注解
- Web Services入门
- 手机端横竖屏检测
- 哈理工 oj2352Save the Little Ant 【所谓的水题】
- 《日本语能力测试阶梯导学读解专训N2》
- 【笔记】深入理解 java 虚拟机---GC.
- pstree命令乱码问题
- jsp九大隐含对象
- MySQL索引和查询优化
- 无限递归循环编译器是如何处理的