GWT报错com.google.gwt.user.server.rpc.UnexpectedException

转载 2012年03月26日 18:42:46

GWT连接mysql数据库

  GWT实现利用jdbc连接mysql数据库,在连接过程中遇到了许多问题,在这里做一下记录。实现过程如下:

  1、首先创建一个项目image .

2、在服务器端实现连接mysql,其代码如下:

。。。

@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
        GreetingService {

    public String greetServer(String input) {
        String serverInfo = getServletContext().getServerInfo();
        String userAgent = getThreadLocalRequest().getHeader("User-Agent");
         Connection con = null; 
            try { 
                Class.forName("com.mysql.jdbc.Driver").newInstance();
                String url = "jdbc:mysql://localhost:3306/test_ssh?autoReconnect=true&useUnicode=true&characterEncoding=utf-8"; 
                con = DriverManager.getConnection(url, "root", "password"); 
                if (!con.isClosed()) 
                    System.out.println("Successfully connected to " 
                            + "MySQL server using TCP/IP…"); 
            } catch (Exception e) { 
                System.err.println("Exception: " + e.getMessage()); 
            } finally { 
                try { 
                    if (con != null) 
                        con.close(); 
                } catch (SQLException e) { 
                } 
            } 
            return "Hello, " + input + "!<br><br>I am running " + serverInfo 
                    + ".<br><br>It looks like you are using:<br>" + userAgent;
    }

。。。

3、添加mysql驱动到war中WEB-INF中lib下面:

image

4、运行,可能会报如下错误:

2010-1-11 5:22:05 com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: [1263187325145000] javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method ‘public abstractjava.lang.String com.easymorse.client.GreetingService.greetServer(java.lang.String)’ threw an unexpected exception:java.lang.ExceptionInInitializerError
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:378)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:581)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:188)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:51)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:121)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
    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:712)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:352)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
    at org.mortbay.jetty.Server.handle(Server.java:313)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
    at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: java.lang.ExceptionInInitializerError
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at com.easymorse.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
    … 30 more
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:151)
    at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkAccess(DevAppServerFactory.java:176)
    at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:288)
    at java.lang.Thread.init(Thread.java:332)
    at java.lang.Thread.<init>(Thread.java:377)
    at java.util.TimerThread.<init>(Timer.java:456)
    at java.util.Timer.<init>(Timer.java:71)
    at java.util.Timer.<init>(Timer.java:122)
    at com.mysql.jdbc.Connection.<clinit>(Connection.java:1087)
    … 40 more

这个的解决办法是:

image

接下来可能会报如下错误:

2010-1-11 5:25:20 com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: [1263187520122000] javax.servlet.ServletContext log: Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method ‘public abstract java.lang.String com.easymorse.client.GreetingService.greetServer(java.lang.String)’ threw an unexpected exception: java.lang.NoClassDefFoundError: Could not initialize class com.mysql.jdbc.Connection
    at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:378)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:581)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:188)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:51)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:121)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
    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:712)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:352)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
    at org.mortbay.jetty.Server.handle(Server.java:313)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
    at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.mysql.jdbc.Connection
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at com.easymorse.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
    … 30 more

其解决办法如下:

image

这样就可以了。

 

注意:3中的解决办法可以直接

image

就不会出以上错误了。


原创…………………………

这是从网上找到别人写的,确实是这个错误的原因,但是当建立项目的时候就勾选了这个,在项目运行中而中途去掉这个勾选,我的项目除了错误,也就是说这里是有配置和jar包的引入所致。对于我的项目,我的的解决办法是去掉勾选之后,删除了一个配置文件,和一些引进来的jar包,成功解决了。

其中的配置文件是appengine-web.xml。

jar包很多:所有用appengine开头的都是。还有其他的


举报

相关文章推荐

异常:Invocation of com.google.gwt.user.tools.WebAppCreator failed. See the error log for more details

做一个开源的项目,前台是用GWT做的,下载并安装好GWT后,新建一个项目时报错: Invocation of com.google.gwt.user.tools.WebAppCreator fa...

GWT RPC 原理浅析一

GWT中前后台交互有多种方式,包括JSON,XML,RPC 其中RPC是GWT提供给我们的功能,他能够让我们直接在前后台传递对象,而无效考虑中间的传递过程。这样的好处是大大提高了我们的开发效率。 ...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

GWT RPC 的使用方式

开发GWT RPC开发时。在GWT 2.2环境下。我遇到了一些问题。不过今天把问题解决。以下是我的开发过程首先导入GWT2.2 Sample目录下的DynaTable工程。这里我使用创建新工程,导入已...

GWT RPC 原理浅析二

前一篇介绍了RPC大体的流程,核心方法是RemoteServiceServlet类中的processPost方法 Java代码   public final void pro...

Browser Caching for GWT RPC Response

最近在学习Web System中的Caching技术,其中一种常见的是browser cache,对HTTP GET response应用cache,并通过某些HTTP Header字段控制cache...

将Eclipse EMF带入Google GWT的世界中来

gwt-html5-graph项目的发布,是WEB开发的一个非常重大的事件。它不仅将强大的图形编辑框架eclipseGEF带入WEB开发中,也将同样强大的建模框架EclipseEMF带入到WEB开发中...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)