public interface LoginService extends RemoteService { public static final String SERVICE_URI = "/login"; public static class Util { public static LoginServiceAsync getInstance() { LoginServiceAsync instance = (LoginServiceAsync) GWT.create(LoginService.class); ServiceDefTarget target = (ServiceDefTarget) instance; target.setServiceEntryPoint(GWT.getModuleBaseURL() + SERVICE_URI); return instance; } } public boolean userIsValid( Map loginData ); }
和Entry类是
public void onModuleLoad() { final LoginServiceAsync loginService = ( LoginServiceAsync )GWT.create( LoginService.class ); ServiceDefTarget endpoint = ( ServiceDefTarget )loginService; String moduleRelativeURL = GWT.getModuleBaseURL()+"login"; endpoint.setServiceEntryPoint( moduleRelativeURL ); this.setLoginPanel(); final AsyncCallback callback = new AsyncCallback() { public void onSuccess( Object result ) { // take the result coming from the server boolean ok = Boolean.valueOf( result.toString() ).booleanValue(); if( ok ) { MessageBox.alert( "Success", "Successfully logged in!"); } else { MessageBox.alert( "Invalid", "Wrong username or password"); } } public void onFailure( Throwable caught ) { MessageBox.alert( "Error", "Error while logging in" ); } }; loginButton = new Button( "Login" ); loginButton.addListener( new ButtonListenerAdapter() { public void onClick( Button button, EventObject e ) { Map loginData = getUserData( formPanel.getForm() ); loginService.userIsValid( loginData, callback ); } }); formPanel.addButton( loginButton ); loginPanel.setBorder( false ); loginPanel.setPaddings( 5 ); loginPanel.add( formPanel ); RootPanel.get().add( loginPanel ); }
这是服务器实现类
public class LoginServiceImpl extends RemoteServiceServlet implements LoginService { public boolean userIsValid( Map loginData ) { boolean accepted = false; String name = loginData.get( "userName" ).toString(); String pswd = loginData.get( "pswd" ).toString(); if( name.equals( "yugal" ) && pswd.equals( "yugal" ) ) { accepted = true; } else { accepted = false; } return accepted; } }
这是web.xml
LoginService org.arosys.server.LoginServiceImpl LoginService /login
控制是在onFailure(Throwable caught)方法,为什么?
有什么问题?