GWT + Glassfish 4:RPC servlet 错误 404

GWT + Glassfish 4 : Error 404 for RPC servlet

我为使用 eclipse 制作的 GWT 应用程序创建了一个 servlet。当我在 TOMCAT 中部署它时,它工作得很好,但在 Glassfish 中我有一个 404 错误。

我没有部署错误,主 html 页面加载良好。但是任何使用 RPC servlet 的东西都会给我这个错误:

com.google.gwt.user.client.rpc.StatusCodeException: 404 Not Found
HTTP Status 404 - Not Found

type Status report

messageNot Found

descriptionThe requested resource is not available.

GlassFish Server Open Source Edition 4.1

我的web.xml是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
    version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">

    <!-- Servlets -->
    <servlet>
        <servlet-name>testServlet</servlet-name>
        <servlet-class>com.test.server.testServiceImpl</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>testServlet</servlet-name>
        <url-pattern>/webclient/test</url-pattern>
    </servlet-mapping>

    <!-- Default page to serve -->
    <welcome-file-list>
        <welcome-file>Webclient.html</welcome-file>
    </welcome-file-list>

</web-app>

在 RPC 的存根中我有这个 com.test.client.testService :

@RemoteServiceRelativePath("test")
public interface testService extends RemoteService {

和 servlet:

public class testServiceImpl extends RemoteServiceServlet implements testService 

备注:

当应用程序在 tomcat 中运行时,如果我在 URL 中写入 servlet 名称,它会显示此错误:

localhost:8080/webclient/webclient/test

状态 HTTP 405 - 此 URL

不支持方法 HTTP GET

看来其实是装好了。但是什么时候在 Glassfish 中:

HTTP 状态 404 - 未找到

我错过了什么?谢谢!

TOMCAT 中 GET 的行为是正确的 (405)..但是 404 很奇怪。您是否在 Glassfish 日志中获得了更多信息? .检查此项目...

0)。检查 URL 的模式。 URL 应该是 http://hostname/nameOfWAR/{urlPatter_into_web.xml}

1). 进行测试以在 Web 应用程序的根目录上部署 HelloWord jsp.. 并检查应用程序是否部署良好并显示一些结果..

2).假设 "webclient" 是您的 WAR 应用程序,您在部署到 Glassfish 时是否已在您的应用程序中导出或包含 gwt-user jar:gwt-user-xxx.jar?如果您使用 Eclipse,您可以使用 Deployment Assembly 或将 jar 定位到 war 的 lib 位置。

3.) 检查编译后的gwt上的序列化策略文件没有问题类。它是一个 .gwt.rpc 文件...这必须在 classpath 上。如果这是问题,应该通过异常等获取更多信息...[也可以覆盖此文件的位置,覆盖 SerializationPolicy]

尝试将 @RemoteServiceRelativePath("test") 更改为 @RemoteServiceRelativePath("/webclient/test")

一般来说,<servlet-mapping>元素应该是你的应用程序的绝对目录路径的形式。您可以阅读这篇有用的文章 http://www.gwtproject.org/doc/latest/tutorial/RPC.html

还有,类 名字应该大写。我明白了,也许是一个测试项目,但要很快适应不好。

已解决!我没有检查 glassfish 的 server.log。转换 RPC servlet 时出错:

rpc servlet 无法转换为 javax.servlet.Servlet

问题是我搞砸了库并在类路径中添加了 javax*,而 Glassfish 不需要它。我删除了留在 domain/lib/ext 中的所有其他库,并且运行良好。

感谢您的支持!