我的代码有什么问题..
Public MyServiceAsync my=GWT.create(MyService.class);
HTML serverResponseLabel = new HTML();
public void onModuleLoad() {
final Label errorLabel = new Label();
RootPanel rootPanel = RootPanel.get();
rootPanel.setSize("100%", "100%");
rootPanel.add(errorLabel);
serverResponseLabel=new HTML();
rootPanel.add(serverResponseLabel);
Button btnSearch = new Button("Search");
rootPanel.add(btnSearch, 558, 110);
btnSearch.setSize("63px", "29px");
btnSearch.addClickHandler(this);
}
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
System.out.println("clicked");
my.myMethod("ka",new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
serverResponseLabel.setHTML(SERVER_ERROR);
}
public void onSuccess(String result) {
serverResponseLabel.setHTML(result);
}
});
}
Sync
public interface MyService extends RemoteService {
public String myMethod(String s);
}
Async
public interface MyServiceAsync {
public void myMethod(String s, AsyncCallback<String> callback);
}
synImple
public class MyServiceImpl extends RemoteServiceServlet implements MyService {
public String myMethod(String s) {
return s+"example";
}
}
我得到一个未捕获的异常转义错误.....
com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:214)
at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:96)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:107)
at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:155)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1308)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1264)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.user.client.rpc.ServiceDefTarget$NoServiceEntryPointSpecifiedException: Service implementation URL not specified
at com.google.gwt.user.client.rpc.impl.RemoteServiceProxy.doPrepareRequestBuilderImpl(RemoteServiceProxy.java:326)
at com.google.gwt.user.client.rpc.impl.RemoteServiceProxy.doInvoke(RemoteServiceProxy.java:265)
at com.test.test.client.MyService_Proxy.myMethod(MyService_Proxy.java:37)
at com.test.test.client.Test.onClick(Test.java:70)
at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54)
at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:1)
at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:204)
at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:96)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:107)
at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:155)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1308)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1264)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Unknown Source)
答案 0 :(得分:9)
您需要在界面中添加@RemoteServiceRelativePath("some.path")
。
请参阅this tutorial。
答案 1 :(得分:0)
运行RPC调用时,开发模式将显示异常NoServiceEntryPointSpecifiedException:未指定服务实现URL。此错误意味着您未在服务界面中指定@RemoteServiceRelativePath,也未通过调用ServiceDefTarget.setServiceEntryPoint()来手动设置目标路径。
ServiceDefTarget target = (ServiceDefTarget) yourService;
target.setServiceEntryPoint(GWT.getModuleBaseURL() + "yourpath");
还要注意与上一个紧密相关的一项, 如果调用RPC调用失败并显示404 StatusCodeException,则您的web.xml可能配置错误。确保您指定了@RemoteServiceRelativePath,并且在web.xml中指定的值与此值匹配,并以war目录中GWT输出目录的位置为前缀。
对于以上给出的每个注释定义,应该在Web部署描述符(即web.xml)中提供服务impl的相应条目。例如,
<servlet>
<servlet-name>sampleServlet</servlet-name>
<servlet-class>samples.gwt.SampleServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sampleServlet</servlet-name>
<url-pattern>/sample-gwt-module/sampleService</url-pattern>
</servlet-mapping>
其中
sample-gwt-module
是模块定义中定义的示例GWT模块的(备用)名称