GWT + Glassfish 4:RPC servlet的错误404

时间:2015-03-06 06:23:15

标签: java tomcat servlets gwt glassfish

我为使用eclipse制作的GWT app创建了一个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 - 此网址不支持HTTP GET

事实上它似乎装得很好。但是什么时候在Glassfish:

HTTP状态404 - 未找到

我失踪了什么?谢谢!

3 个答案:

答案 0 :(得分:2)

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

0)。检查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]

答案 1 :(得分:2)

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

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

请注意,课程应以大写字母命名。我知道也许这是一个测试项目,但很快就习惯了。

答案 2 :(得分:0)

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

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

问题是我搞乱了libs并在类路径中添加了javax *,而Glassfish并不需要这个。我删除了我在domain / lib / ext中留下的所有其他库,并且工作得很好。

感谢您的支持!