GWT RPC jetty服务器期间出错404

时间:2011-09-03 15:24:50

标签: gwt rpc

我刚写了简单的RPC调用,当我尝试得到以下错误时,你能不能帮我解决这个问题..

[WARN] 404 - POST /com.sribalajiele.gwt.client.SriBalajiEle/emailRpcService (127.0.0.1) 
Email Failure404 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 404 NOT_FOUND</title>

以下代码。

/*
 * Copyright (c) Balaji electricals AG 2011, All Rights Reserved
 */
package com.sribalajiele.gwt.client.client;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

/**
 * @author kdel.
 * This interface provides Email Service.
 *
 */
@RemoteServiceRelativePath("emailRpcService")
public interface EmailRpcService extends RemoteService {

   public WriteToUsForm sendEmail(WriteToUsForm writeToUsForm) throws IllegalArgumentException;
}


/*
 * Copyright (c) Balaji electricals 2011, All Rights Reserved
 */
package com.sribalajiele.gwt.client.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * @author kdel
 * Async service for Email.
 */
public interface EmailRpcServiceAsync {
   void sendEmail(WriteToUsForm writeToUsForm, AsyncCallback<WriteToUsForm> asyncCallback)
   throws IllegalArgumentException;
}


public final class EmailRpcServiceImpl extends RemoteServiceServlet implements EmailRpcService {

   /**
    * Default serialVersionUID.
    */
   private static final long serialVersionUID = 1L;

   @Override
   public WriteToUsForm sendEmail(WriteToUsForm writeToUsForm) throws IllegalArgumentException  {  
          System.out.println("send Email called");
    }
}

web.xml

<servlet>
    <servlet-name>emailService</servlet-name>
    <servlet-class>com.sribalajiele.gwt.client.server.EmailRpcServiceImpl</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>emailService</servlet-name>
    <url-pattern>sriBalajiEle/emailRpcService</url-pattern>
</servlet-mapping>

4 个答案:

答案 0 :(得分:2)

Finally i could correct my self, may be this is use full for others.

1) @RemoteServiceRelativePath("emailRpcService")
public interface EmailRpcService extends RemoteService {

2) In *Module*.gwt.xml
<servlet class="com.sribalajiele.ui.server.EmailRpcServiceImpl" path="/emailRpcService"/>

3) Register your servlet in web.xml
<servlet>
        <servlet-name>eamilService</servlet-name>
        <servlet-class>com.sribalajiele.ui.server.EmailRpcServiceImpl</servlet-class>
    </servlet>
    <servlet-mapping> 
        <servlet-name>eamilService</servlet-name> 
        <url-pattern>/com.sribalajiele.ui.SriBalaji/emailRpcService</url-pattern> 
    </servlet-mapping>

4) Usage:

  final EmailRpcServiceAsync emailRpcServiceAsync = (EmailRpcServiceAsync) GWT.create(EmailRpcService.class);
      ServiceDefTarget serviceDef = (ServiceDefTarget) emailRpcServiceAsync;
      serviceDef.setServiceEntryPoint(GWT.getModuleBaseURL() + "emailRpcService");
emailRpcServiceAsync.sendEmail(parameter, new AsyncCall()) {
onSuccess() { }
onFailure() { }
}

希望这会有所帮助......

答案 1 :(得分:1)

问题是您将servlet映射到/sriBalajiEle/emailRpcService,但请求正在发送到/com.sribalajiele.gwt.client.SriBalajiEle/emailRpcService。请求发送到的URL由GWT以/${moduleName}/relativePath的形式生成。如果您在GWT模块的顶部包含以下内容,则应修复404。

<module rename-to="sriBalajiEle">

答案 2 :(得分:0)

1)在您的界面中也包括注释。

@RemoteServiceRelativePath("emailRpcService")
public interface EmailRpcServiceAsync {
   void sendEmail(WriteToUsForm writeToUsForm,
     

AsyncCallback asyncCallback)          抛出IllegalArgumentException;       }

2)并将您的网址映射更改为以下内容。

    <url-pattern>com.sribalajiele.gwt.EmailRpcService/emailRpcService</url-pattern>

对于我的情况,网址映射让我头疼几个小时。希望这会有所帮助。

答案 3 :(得分:0)

404错误将站点为url,我必须确保404消息中的url是我web.xml中的url

<servlet-mapping>
    <servlet-name>messageServiceImpl</servlet-name>
    <url-pattern>/com.mbe.site.main/message</url-pattern>
</servlet-mapping>