从我读过的所有内容来看,applet 可以调用它自己的服务器提供的任何服务。这就是为什么我编写并启动了一项服务(在 netbeans 中),我可以在我的浏览器中看到它
http://localhost:12345/server?wsdl
为了连接到服务,我使用了 wsimport 并将文件放在我的小程序目录中,然后我清理并构建了项目。
如果我同时启动(服务+小程序)它工作正常,当我删除策略文件时,它不会。
Caused by: java.security.AccessControlException: access denied
("java.util.PropertyPermission" "xml.catalog.ignoreMissing" "read")
我在 Netbeans 中启动了服务并将小程序放在我的本地服务器(xampp)上,我可以通过它访问它
http://localhost/sql/mainapplet.html
但什么也没发生。我做错了什么?
这是代码:
服务器项目:
CP.java
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService(targetNamespace = "GUI")
@SOAPBinding(style = Style.RPC)
public class CP {
public String getResults(String u, String p, String s, String se, String q) {
...
}
}
服务器.java
public class Server {
public static void main(String[] args) {
CP server = new CP();
Endpoint e = Endpoint.publish("http://localhost:12345/server", server);
}
}
客户项目:CP.java
package gui;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.Action;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.4-b01
* Generated source version: 2.2
*
*/
@WebService(name = "CP", targetNamespace = "GUI")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface CP {
/**
*
* @param arg4
* @param arg3
* @param arg2
* @param arg1
* @param arg0
* @return
* returns java.lang.String
*/
@WebMethod
@WebResult(partName = "return")
@Action(input = "GUI/CP/getResultsRequest", output = "GUI/CP/getResultsResponse")
public String getResults(
@WebParam(name = "arg0", partName = "arg0")
String arg0,
@WebParam(name = "arg1", partName = "arg1")
String arg1,
@WebParam(name = "arg2", partName = "arg2")
String arg2,
@WebParam(name = "arg3", partName = "arg3")
String arg3,
@WebParam(name = "arg4", partName = "arg4")
String arg4);
}
CPService.java
package gui;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.4-b01
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "CPService", targetNamespace = "GUI", wsdlLocation = "http://localhost:12345/server?wsdl")
public class CPService
extends Service {
private final static URL CPSERVICE_WSDL_LOCATION;
private final static WebServiceException CPSERVICE_EXCEPTION;
private final static QName CPSERVICE_QNAME = new QName("GUI", "CPService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://localhost:12345/server?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
CPSERVICE_WSDL_LOCATION = url;
CPSERVICE_EXCEPTION = e;
}
public CPService() {
super(__getWsdlLocation(), CPSERVICE_QNAME);
}
public CPService(WebServiceFeature... features) {
super(__getWsdlLocation(), CPSERVICE_QNAME, features);
}
public CPService(URL wsdlLocation) {
super(wsdlLocation, CPSERVICE_QNAME);
}
public CPService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, CPSERVICE_QNAME, features);
}
public CPService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public CPService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns CP
*/
@WebEndpoint(name = "CPPort")
public CP getCPPort() {
return super.getPort(new QName("GUI", "CPPort"), CP.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns CP
*/
@WebEndpoint(name = "CPPort")
public CP getCPPort(WebServiceFeature... features) {
return super.getPort(new QName("GUI", "CPPort"), CP.class, features);
}
private static URL __getWsdlLocation() {
if (CPSERVICE_EXCEPTION!= null) {
throw CPSERVICE_EXCEPTION;
}
return CPSERVICE_WSDL_LOCATION;
}
}
MainApplet.java
package gui;
public class MainApplet extends javax.swing.JApplet {
...
CPService cps = new CPService();
CP cproc = cps.getCPPort();
txtResult.setText(cproc.getResults("a","b","j","s", "q"));
}
HTML 文件:
<HTML>
<BODY>
<P>
<APPLET codebase="client/build/classes" code="gui/MainApplet.class" archive="client/dist/client.jar" width=1400 height=800></APPLET>
</P>
</BODY>
</HTML>