GWT:Servlet URL映射给出了404错误

问题描述:

我已经阅读了其他GWT Servlet问题,但我仍然无法解决我的问题。我的软件包叫做Maps,它有一个名为MyService的服务(根据GWT教程设置)。 web.xml文件包括以下内容:GWT:Servlet URL映射给出了404错误

<servlet> 
    <servlet-name>MyServiceImpl</servlet-name> 
    <servlet-class>com.xerox.maps.maps.server.MyServiceImpl</servlet-class> 
</servlet> 

<servlet-mapping> 
    <servlet-name>MyServiceImpl</servlet-name> 
    <url-pattern>/Maps/service</url-pattern> 
</servlet-mapping> 

在为MyService,我也行:

@RemoteServiceRelativePath("service") 
public interface MyService extends RemoteService { ... 

但是,当我试图让一个RPC调用,没有抛出一个错误。错误的详细信息说它是一个404 HTTP错误。我如何解决这个问题,以确保映射是正确的?

编辑7.27

MyService.java包含注释:

@RemoteServiceRelativePath("service") 

和web.xml包含:

<servlet-name>MyServiceImpl</servlet-name> 
<url-pattern>/com.x.maps.Maps/service</url-pattern> 

如果我遵循的Firebug XHR,它表明我有一个电话com.x.maps.Maps

+0

你有链接到教程?我一直在GWT最近编码并能够帮助(如果我看不到了。问题:)) – user710502

+0

当然:我一直在使用[这一个](http://代码。主要以及[此其他教程](http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideRPCDeployment)。谢谢! – simchona

+0

你如何在xml文件中设置入口点?你使用rpc.AsyncCallback? – user710502

404当通过GWT错误地推断服务端点路径时,通常会抛出Not Found。尝试删除@RemoteServiceRelativePath("service")并重新编译并检查,如果不起作用,则手动查找服务的URL端点(通过从浏览器点击可能的路径,直到错误更改为500内部错误),然后将正确的路径作为参数提供给@RemoteServiceRelativePath("correct/path")。很少有试验所有的意见后,我会尝试马上就是@RemoteServiceRelativePath("/Maps/service")@RemoteServiceRelativePath("Maps/service")没有斜杠

+0

如何在http://127.0.0.1:8888/Maps.html?gwt.codesvr=127.0.0.1:9997加载代码时更改路径? – simchona

+0

你有没有尝试删除RemoteServiceRelativePath注释?并回答你的问题,关于如何更改路径:使用Firebug Net面板并转到XHR部分(XmlHttpRequests),首先找出正在做什么请求以及到哪个路径。知道这一点,将GWT.create()返回的对象转换为RemoteServiceProxy并调用setServiceEndpoint()方法,使用正确的路径或正确的服务端点 – Zasz

+0

我尝试删除注释 - 是否应该匹配标记?我不确定什么是萤火虫。我正在使用Eclipse。我很抱歉,这让我花了很长时间才得到,但GWT和servlets对我来说非常新颖。 – simchona

新的答案:

酷,你进步了! 你打这个网址 -

http://127.0.0.1:8888/com.x.maps.maps.Maps 

有了这个POST数据我假设 - /%7C98544A4AED8C7D42E80C55859E9CEC4C%7Ccom.x.maps.maps.client.MyService%7CreadFile%7Cjava.lang.String/2004016611%7CPrinterList.xls%7C1%7C2%7C3%7C4%7C1%7C5%7C6%7C

这就是问题的所在,你的servlet被映射到在来到<url-pattern>/Maps/service</url-pattern> XHR请求作出回应,但你打/com.x.maps.maps.Maps代替。因此你得到404路径找不到状态码。

Alter the url-pattern on the server-side web.xml to match what the browser is making, 
OR 
Alter the GWT code using the RemoteServiceRelativePath annotation to make the request to /Maps/service instead of to /com.x.maps.maps.Maps 
+0

明天我会试试这个。感谢您真的耐心等待 - 我知道这可能是多么的乏味 – simchona

+1

不用担心,配置总是令人头痛,直到你得到它的工作:) – Zasz

+0

好吧,我正在编辑我的问题,以显示最新的配置。我试图编辑url模式,但我的404仍然存在。 – simchona

我有同样的问题,但我解决它改变了Servlet的URL模式在web.xml

尝试把你的web.xml中的目录路径您的GWT在WEB-INF/deploy之后生成javascript模块。在我的情况:

<url-pattern>/gwtmodulemain/selection</url-pattern> 

你也可以在你的gwt.xml文件重命名你的模块名称:

<module rename-to='gwtmodulemain'> 

,所以你可以参考你的模块从你的HTML这样:

<script type="text/javascript" language="javascript" src="gwtmodulemain/gwtmodulemain.nocache.js"></script> 

祝你好运!

根据该教程: https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC

该servlet映射应该由该模块的“重命名到”与服务“RemoteServiceRelativePath”。所以,如果你有,你* .gwt.xml文件,下面一行:

<module rename-to='XXX'> 

而在你的* Service.java文件,你有下面这行:

@RemoteServiceRelativePath("YYY") 

然后,在你的“的web.xml”文件,你应该有下面几行:

<servlet-mapping> 
    <servlet-name>...servlet-name> 
    <url-pattern>/XXX/YYY</url-pattern> 
    </servlet-mapping>