无法使 RemoteServiceRelativePath 和 XML 工作 (GWT)
我认为 GTW 项目的 XML 文件配置错误,因为当我尝试联系远程服务时,出现此错误:“访问 /myresults/compress 时出现问题。原因:NOT_FOUND”。如果有人可以帮助我,请在下面找到我的代码的重要部分,我认为它与 RemoteServiceRelativePath 和我的 XML 有关。
更新:当我在 web.xml 中更改 URL-PATTERN 的内容时,我仍然收到路径 /myresults/compress 完全相同的消息。
CompressionService.java
package myProject.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/* The client side stub for the RPC service. */
@RemoteServiceRelativePath("compress")
public interface CompressionService extends RemoteService {
String compress(String name) throws IllegalArgumentException;
}
CompressionServiceImpl.java
package myProject.server;
import myProject.client.CompressionService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/* The server side implementation of the RPC service. */
public class CompressionServiceImpl extends RemoteServiceServlet implements
CompressionService {
public String compress(String input) throws IllegalArgumentException {
String output = "aaaa";
return output;
}
}
CompressionService.java
package myProject.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
/* The async counterpart of <code>CompressService</code> */
public interface CompressionServiceAsync {
void compress(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>compressionService</servlet-name>
<servlet-class>myProject.server.CompressionServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>compressionService</servlet-name>
<url-pattern>/myresults/compress</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>MyResults.html</welcome-file>
</welcome-file-list>
</web-app>
MyResults.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='myresults'>
<inherits name='com.google.gwt.user.User'/>
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<entry-point class='myProject.client.MyResults'/>
<source path='client'/>
<source path='shared'/>
</module>
MyResults.java
private final CompressionServiceAsync compressionService = GWT.create(CompressionService.class);
compressionService.compress(text, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
download.setText(caught.getMessage()));
}
public void onSuccess(String result) {
download.setText(result);
}
});
I think I have a bad configuration of my XML files for my GTW project because when I try to contact the remote service I get this error: "Problem accessing /myresults/compress. Reason: NOT_FOUND". Please find below the important pieces of my code if anyone can help me, I think it is related to RemoteServiceRelativePath and my XML.
UPDATE: When I change in web.xml the content of URL-PATTERN I still get exactly the same message with path /myresults/compress.
CompressionService.java
package myProject.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/* The client side stub for the RPC service. */
@RemoteServiceRelativePath("compress")
public interface CompressionService extends RemoteService {
String compress(String name) throws IllegalArgumentException;
}
CompressionServiceImpl.java
package myProject.server;
import myProject.client.CompressionService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/* The server side implementation of the RPC service. */
public class CompressionServiceImpl extends RemoteServiceServlet implements
CompressionService {
public String compress(String input) throws IllegalArgumentException {
String output = "aaaa";
return output;
}
}
CompressionService.java
package myProject.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
/* The async counterpart of <code>CompressService</code> */
public interface CompressionServiceAsync {
void compress(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>compressionService</servlet-name>
<servlet-class>myProject.server.CompressionServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>compressionService</servlet-name>
<url-pattern>/myresults/compress</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>MyResults.html</welcome-file>
</welcome-file-list>
</web-app>
MyResults.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='myresults'>
<inherits name='com.google.gwt.user.User'/>
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<entry-point class='myProject.client.MyResults'/>
<source path='client'/>
<source path='shared'/>
</module>
MyResults.java
private final CompressionServiceAsync compressionService = GWT.create(CompressionService.class);
compressionService.compress(text, new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
download.setText(caught.getMessage()));
}
public void onSuccess(String result) {
download.setText(result);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜你已经在思考正确的方向了。问题似乎是您的
@RemoteServiceRelativePath
和 web.xmlurl-mapping
彼此不一致。可能将 web.xml 中的 servlet-mapping 更改为以下内容可以解决您的问题:
I guess you are already thinking on the right lines. The problem seems to be that your
@RemoteServiceRelativePath
and web.xmlurl-mapping
doesn't agree with each other.Probably changing servlet-mapping in web.xml to following will fix your problem:
我遇到了类似的问题,即使删除了所有 GWT 生成的文件和浏览器历史记录,应用程序中的 web.xml 中的 servlet 路径也没有更新。
更奇怪的是,这个问题只出现在 Chrome 上,而没有出现在 Firefox 上。
事实证明,Chrome 仍在从 GWT 临时目录加载旧版本的 web.xml,该目录在系统启动时显示:\AppData\Local\Temp\gwt-codeserver-3864057753329430362.tmp
超级开发模式启动
workDir: C:\Users
从此临时目录中删除数据后,该应用程序也在 Chrome 中进行了更新。
I ran into a similar issue where the servlet path from web.xml was not updated in the application even after deleting all GWT generated files and browser history.
Even more strangely, the issue appeared only on Chrome but not on Firefox.
Turns out that Chrome was still loading the old version of web.xml from GWT temporary directory which is displayed at system start-up:
Super Dev Mode starting up
workDir: C:\Users<username>\AppData\Local\Temp\gwt-codeserver-3864057753329430362.tmp
After removing the data from this temporary directory as well, the application was updated in Chrome too.