Web Service Tip: JSPs Calling Web Services
来源:互联网 发布:网络尖兵防御 编辑:程序博客网 时间:2024/06/06 01:18
http://radio.weblogs.com/0132036/2003/12/11.html
Web Service Tip: JSPs Calling Web Services How do I call a Web service from a JSP? Seems like a simple question but it turns out there are many ways - some quick and dirty and others more correct. Let's not debate correctness (do you really want to do this?!) and first solve the problem. Imagine, if you will, I have generated a stub from the wsdl of the greeting Web service built a few days ago (again, I refer you to the OTN tutorial step 16 for more details on generating the stub). If I add a main method to that stub, I can easily test that stub against my Web service: public static void main(String[] args) { That bit of code, will become the foundation of how to do my first cut of calling of a Web service from a JSP. The JSP page I want to hook it into looks like this:
First I would like to make a direct call from my JSP. All I have to do is add a scriplet based on that above code: <%@ page contentType="text/html;charset=windows-1252" import="com.rpc.GreetingServiceStub" %> Note the import at the top of com.rpc.GreetingServiceStub which is the stub itself. Not particularly elegant, but it gets the job done. Abstracting it a little further, I could investigate Oracle's Web service tag library which takes away a bit of the code and makes it a little more declarative. The extra work required here is of course reading the WSDL to get the binding, portType and the like. See below for the same example using the tag library: <%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/wstaglib.tld" prefix="wstag"%>
<br> </body> If you look again at the WSDL, you will see all the settings that were passed to the tags - e.g. GreetingBinding from the binding section and operation name from the portType section. If you plan on trying this out yourself, you are probably wondering where this Web services tag library jar and tld is located. If you look in your OracleAS 9.0.4 distribution, you will find the ojsputil.jar located in the <Oracle_Home>j2eehomejsplibtaglib - inside is the TLD. Most likely in a larger application, for example using a more typical MVC framework like Struts, the call to from stub would be more likely be in an Apache Struts action or delegated to from a Struts action, rather than in the JSP page itself. However, for the folks doing quick and dirties out there, these two routes can be a quick way to hook your Web service to a JSP. As a by the by, if you are an Oracle Portal user you may want to investigate the OmniPortlet, which makes this whole exercise a declarative effort rather than a programmatic one. |
- Web Service Tip: JSPs Calling Web Services
- Calling Web Services Asynchronously
- Calling web service using AJAX
- Reporting Services : Web Service
- Reporting Services- Web Service
- Calling Web Service from Client-Side JavaScript
- Calling Web Services From Html Pages using Javascript
- Patterns: Service Oriented Architecture And Web Services
- 启用 Master Data Services 的 Web Service
- 使用HP Service Test测试Web Services
- Amazon Web Services S3 (Simple Storage Service)
- Amazon Web Services SES(Simple Email Service)
- Service References to a MTOM web services
- 转: Calling a SAP Web Service from VS.Net
- Creating and Calling ASP.NET AJAX Web Service
- Calling a web-service from a Unity3D scene
- SharePoint Web Service系列:编写自定义SharePoint Web Services之一
- Enabling Semantic Web Services: The Web Service Modeling Ontology
- CIO如何转型
- VB版2004年度专家榜(2004年度发的回复所得分)
- 浅析C语言的一个关键字——register
- ASP.NET中利用DataGrid的自定义分页功能和存储过程结合实现高效分页
- 动手扩充FreeTextBox的功能
- Web Service Tip: JSPs Calling Web Services
- 程序员转型:条条大道通罗马
- 用 XDoclet 减少代码膨胀[摘]
- 给你的Websphere 5.1.x 添加Trace
- VB版2004年度专家榜(揭帖时间为2004年度的得分汇总)
- 什么是JavaBean!
- 软件设计师大纲
- sample.l
- JDBC连接SYBASE的3种方法