0

即使浏览了大量博客,我也找不到解决这个问题的方法。

  1. 是的,我的模型(POJO)实现了 Serializable(也尝试了 IsSerializable)
  2. 我之前在 RPC 上取得了成功,但我不知道为什么现在会出现此错误:

    com.google.gwt.user.client.rpc.StatusCodeException: 500 The call failed on the server; see server log for details
        at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209)
        at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
        at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
        at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
        at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Unknown Source)
    

服务器堆栈跟踪:

Starting Jetty on port 8888
        [WARN] Exception while dispatching incoming RPC call
        com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract com.project.package.gwt.shared.User com.project.package.gwt.client.ProService.loginServer(java.lang.String,java.lang.String)' threw an unexpected exception: java.lang.NullPointerException
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:385)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:588)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
    Caused by: java.lang.NullPointerException
    at com.project.package.gwt.server.ProServiceImpl.loginServer(ProServiceImpl.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
    ... 22 more

也可以通过电线序列化字符串吗?

并且显示空指针异常,因为 RPC 不成功。如果 RPC 成功,我希望返回一个对象

添加源代码

com.project.package.gwt.server.ProServiceImpl.loginServer.java

public User loginServer(String uname, String password) {

    System.out.println("Making User Login Call to the server");
    System.out.println("Username is : "+uname+" Password is : "+password);

    return loginObj.validateLogin(uname, password);
}

validate login 方法,用于验证用户

public User validateLogin(String username, String password) {

    System.out.println("Inside Server/");
    //ApplicationContext ac = new ClassPathXmlApplicationContext("jdbc-context.xml");
    ApplicationContext ac = new ClassPathXmlApplicationContext("jdbc-context.xml");
    DataSource dataSource = (DataSource) ac.getBean("dataSource");

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

    System.out.println("Inside Server/Login Handler");

    String result = null;
    String query = "SELECT emp_name FROM emp_name = ? AND emp_password = ?";

    try {
        result = jdbcTemplate.queryForObject(query, String.class);
    } catch (EmptyResultDataAccessException e) {
        // TODO: handle exception#
        e.printStackTrace();
    }

    if (result == null) {
        System.out.println("The result of the SQL query is null");
    } else {
        System.out.println("The result of the SQL query is " + result);
        user.setUsername(result);
    }
    return user;
}

}

控件未进入验证登录方法(内部服务器/未打印),这意味着我的 RPC 失败,因此是 NPE

4

2 回答 2

3

你的 99%loginObj是空的。请确保这是真的。

System.out.println(loginObj == null);
return loginObj.validateLogin(uname, password);

并将您的第 85 行ProServiceImpl.java源代码提供给我们。我们还能等多久?

于 2012-07-17T14:22:01.603 回答
0

那么你在 com.project.package.gwt.server.ProtasServiceImpl.loginServer(ProtasServiceImpl.java:85) 有一个 java.lang.NullPointerException

您需要确定是什么原因造成的。

于 2012-07-17T11:46:56.933 回答