GWT RPC: простое сообщение с сервера - PullRequest
0 голосов
/ 22 января 2012

Я хочу отобразить сообщение с сервера, когда пользователь нажимает кнопку на веб-странице клиента. Вот мой код Может кто-то это увидеть. Он работает, но не работает, когда я ввожу имя и нажимаю кнопку «Нажми». Отображает сообщение «Проверьте свои входы»

вот трассировка стека:

[WARN] 404 - POST /lumiproj/testService (127.0.0.1) 1406 bytes
   Request headers
      Host: 127.0.0.1:8888
      Connection: keep-alive
      User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
      Accept: */*
      Accept-Encoding: gzip,deflate,sdch
      Accept-Language: en-US,en;q=0.8
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
      Referer: http://127.0.0.1:8888/LumiProj.html?gwt.codesvr=127.0.0.1:9997
      Content-Length: 159
      Origin: http://127.0.0.1:8888
      X-GWT-Module-Base: http://127.0.0.1:8888/lumiproj/
      X-GWT-Permutation: HostedMode
      Content-Type: text/x-gwt-rpc; charset=UTF-8
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1406

web.xml

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" версия = "2.5" XMLNS = "http://java.sun.com/xml/ns/javaee">

LumiProjServiceImpl com.hello.server.LumiProjServiceImpl

LumiProjServiceImpl / Lumiproj / Приветствуйте

LumiProj.html

класс точки входа

package com.hello.client;

//import rpctest.client.RpctestService;
//import rpctest.client.RpctestServiceAsync;

import com.hello.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class LumiProj implements EntryPoint {

    final TextBox nameText = new TextBox();
    final Label nameLabel = new Label("Enter name");
    final Button pressBtn = new Button("Press!");
    final Button exitBtn = new Button("exit");
    //final Label errorLabel = new Label();
    private VerticalPanel mainpanel = new VerticalPanel();
    private HorizontalPanel addpanel1 = new HorizontalPanel();
    private HorizontalPanel addpanel2 = new HorizontalPanel();




    private final LumiProjServiceAsync calNumbers = GWT
            .create(LumiProjService.class);

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {

        addpanel1.add(nameLabel);
        addpanel1.add(nameText);
        addpanel2.add(pressBtn);
        addpanel2.add(exitBtn);
        mainpanel.add(addpanel1);
        mainpanel.add(addpanel2);

        pressBtn.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {

            String name = nameText.getValue();  

            calNumbers.calNumbers(name,
                new AsyncCallback<String>() {
                public void onFailure(Throwable caught) {
                    // Show the RPC error message to the user
                        Window.alert("check your inputs");
                    }

                @Override
                public void onSuccess(String result) {
                // TODO Auto-generated method stub
                    Window.alert("answer="+result);
                }
            });}
        });
        // We can add style names to widgets
        //sendButton.addStyleName("sendButton");

        // Add the nameField and sendButton to the RootPanel
        // Use RootPanel.get() to get the entire body element

        /*RootPanel.get("nameFieldContainer").add(nameField);
         * 
        RootPanel.get("sendButtonContainer").add(sendButton);
        RootPanel.get("errorLabelContainer").add(errorLabel);*/
        RootPanel.get().add(mainpanel);

    }
}

сервисные интерфейсы:

package com.hello.client;

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

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

    String calNumbers(String name) throws IllegalArgumentException;
}

------------------
package com.hello.client;

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

public interface LumiProjServiceAsync {

    void calNumbers(String name,
            AsyncCallback<String> callback);
}

serviceIMPL

package com.hello.server;

import com.hello.client.LumiProjService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class LumiProServiceImpl extends RemoteServiceServlet  implements LumiProjService {

    @Override
    public String calNumbers(String name) throws IllegalArgumentException {

        String h = "Hello";

        return h+" "+name;
    }
}

1 Ответ

0 голосов
/ 22 января 2012

Можете ли вы опубликовать трассировку стека ошибок gwt (если существует) или текст Throwable в

    public void onFailure(Throwable caught) 
?

Также, пожалуйста, опубликуйте свой файл web.xml, возможно, есть ошибкав отображении пути сервлета

...