用.net webservice很容易,java webservice不熟,求解救
http://blog.csdn.net/flightme/article/details/6977191我是在这篇文章看到webservice的教程,就是用myeclipse开发webservice,学习整个教程没有问题,很成功。
现在的问题是:我想像.net那样可以用jquery像这样去访问
$.ajax({
url:'ws/test.asmx/gettest'
data:{},
success:function(data){console.log(data)}
})
但是java生成的webservice却是http://localhost:8080/myws/APort?wsdl这种形式,请问各位大神,我有办法像.net生成的webservice一样用jquery去访问吗,直接写url:‘http://localhost:8080/myws/Aport?wsdl/funcitonname’,这样是不行的。
总结一下吧:就是如何用js去访问java的webservice。 java myeclipse webservice jquery ajax --------------------编程问答-------------------- ?wsdl是给你看服务设定的信息
你一样可以用service/functionname?para来访问 --------------------编程问答--------------------
这位大大谢谢你,但是我还是不太清楚怎么写,能写的稍微全一些吗?。。
这样?http://localhost:8080/myws/Aport?wsdl/service/functionname?para
这样?http://localhost:8080/myws/AService/functionname?para
我都没有试成功~ --------------------编程问答-------------------- 自己给自己顶一下!! --------------------编程问答--------------------
正确的访问方式是这样的:
http://localhost:8080/myws/AService/方法名?参数名1=参数值1&参数名2=参数值2
如果这样不行,那一定会报异常,页面会显示有异常,而后台会有具体的异常信息,这样的话贴异常过来才能判断哪出的问题。 --------------------编程问答--------------------
按照你的作法输入了,还是出现错误了。
404~额,是我的xml配置问题吗?
--------------------编程问答-------------------- 后台在console对话框里没有任何的提示。。我用的是myeclipse自带的tocat。
建webservice是完全按照
http://blog.csdn.net/flightme/article/details/6977191
这篇文章的 教程 来建立的。
不知道哪里出了错,大神,求救啊 --------------------编程问答-------------------- 如果你确定在初始化时没有出现任何异常,那么404说明是你输入的webservice路径与你配置的路径不同。
默认的配置应该是htt://网站域名/应用名/webservice配置的相对路径/方法名 --------------------编程问答-------------------- 哦~
在server启动的时候,出现这样的错误。
The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Program Files\Genuitec\Common\binary\com.sun.java.jdk.win32.x86_1.6.0.013\bin;D:\Program Files\Genuitec\Common\plugins\com.genuitec.eclipse.easie.tomcat.myeclipse_8.5.0.me201003121946\tomcat\bin
另外我注意到我项目的 webroot/web-inf/lib 文件夹是空的
是否没有引入jar包呢。
而教程中有这样的一段,但是没有告诉我怎样添加jar包
如果是要导入jar包,怎么导呢,从网上下载这些个jar包吗 --------------------编程问答-------------------- 少包的话肯定是要从网上找了 --------------------编程问答--------------------
大神,我导入包了,还是不能用你刚才说的
http://localhost:8080/myws/AService/方法名?参数名1=参数值1&参数名2=参数值2
去访问webservice。求救啊 --------------------编程问答--------------------
又回到我7楼的回答了.... --------------------编程问答--------------------
大神啊,配了半天没配出来啊,这个东西xml配置好像也没法调试是吧~
项目结构现在是这样的:
-----------------------------------------------------------
有三个配置文件:
AService.wsdl如下:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.3-hudson-390-. -->
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://sdfas/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AService" targetNamespace="http://sdfas/">
<types>
<xsd:schema>
<xsd:import namespace="http://sdfas/" schemaLocation="AService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="getStr">
<part element="tns:getStr" name="parameters"/>
</message>
<message name="getStrResponse">
<part element="tns:getStrResponse" name="parameters"/>
</message>
<portType name="ADelegate">
<operation name="getStr">
<input message="tns:getStr"/>
<output message="tns:getStrResponse"/>
</operation>
</portType>
<binding name="APortBinding" type="tns:ADelegate">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getStr">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="AService">
<port binding="tns:APortBinding" name="APort">
<soap:address location="http://localhost:8080/newws/APort"/>
</port>
</service>
</definitions>
---------------------------------------------------------------------------
sun-jaxws.xml如下:
<?xml version = "1.0"?>
<endpoints version="2.0"
xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
<endpoint name="APort" implementation="sdfas.ADelegate"
url-pattern="/APort">
</endpoint></endpoints>
---------------------------------------------------------------------------
web.xml 如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<description>JAX-WS endpoint - AService</description>
<display-name>AService</display-name>
<servlet-name>AService</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AService</servlet-name>
<url-pattern>/APort</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener></web-app>
大神能帮我看一下吗?求救啊,分少可以加~
--------------------编程问答-------------------- xml配置如果不正确,那初始化时肯定后台是有错误提示的。
你的web.xml里配置应该是http://localhost:8080/APort,而不是AService --------------------编程问答-------------------- 还是搞不定,给自己顶一下!
补充:Java , Web 开发