运行GWT应用程序时异常

编程入门 行业动态 更新时间:2024-10-10 04:23:20
本文介绍了运行GWT应用程序时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我已经构建了我的第一个GWT应用程序。不会导致运行时错误的编译错误。但是,当应用程序加载到浏览器中(使用Interner Explorer)并输入用户名和密码字段来验证用户时,会引发异常。使用GWT-RPC方法,提供了整个代码和接口。 我正在使用 HSQL 进行数据库连接(后端)。

----------- ------- CODE(CLIENT)

package com.vin.client; 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.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.Label; import com.google.gwt.user.client.ui.PasswordTextBox; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.TextBox; public class HelloWorld实现EntryPoint { private UserServiceAsync UserService =(UserServiceAsync)GWT.create(UserService.class); public void onModuleLoad(){ Button click = new Button(Click Here); 标签名=新标签(输入名称); Label passwrd = new Label(Enter Password); final TextBox t_name = new TextBox(); final PasswordTextBox t_passwrd = new PasswordTextBox(); click.addClickHandler(new ClickHandler(){ public void onClick(ClickEvent ev){ String temp_user = t_name.getText(); String temp_pass = t_passwrd.getText() ; UserService.loginuser(temp_user,temp_pass,new AsyncCallback< String>(){ public void onFailure(Throwable catch){ Window.alert(请输入有效的详细信息); } public void onSuccess(String result){ Window.alert(Welcome); // Window.open(127.0.0.1:8888/ ExWid.html?gwt.codesvr = 127.0.0.1:9997,Dem,null); } }); } }); RootPanel.get()。add(name); RootPanel.get()。add(t_name); RootPanel.get()。add(passwrd); RootPanel.get()。add(t_passwrd); RootPanel.get()。add(click); } }

----------- ------------------客户界面(1)

package com。 vin.client; import com.google.gwt.user.client.rpc.RemoteService; public interface UserService extends RemoteService { public String loginuser(String username,String password); }

---------------- ------------ CLIENT ASYNC INTERFACE

package com.vin.client; import com.google.gwt.user.client.rpc.AsyncCallback; public interface UserServiceAsync { public void loginuser(String username,String password,AsyncCallback< String> callback); }

---------------- ----------客户端服务器(SERVER)的实现...数据库连接

package com.vin 。服务器; import java.sql.DriverManager; import java.sql.ResultSet; import com.google.gwt.dev.generator.ast.Statement; import com.google.gwt.user.client.Window; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.vin.client.UserService; public class UserServiceImpl extends RemoteServiceServlet implements UserService { private static final long serialVersionUID = 1L; public String loginuser(String username,String password){ try { java.sql.Connection con = null; Class.forName(org.hsqldb.jdbcDriver); con = DriverManager.getConnection(jdbc:hsqldb:hsql:// localhost /,SA,); 语句st =(Statement)con.createStatement(); ResultSet rs =((java.sql.Statement)st).executeQuery(select username,lgfrm); String user = rs.getString(1); String pass = rs.getString(2); if(username.equals(user)&& password.equals(pass)){ Window.alert(success); } } catch(异常ae){} returnsuccess; } }

----------- -------我尝试验证用户的例外列表

15:22:54.583 [错误] [ helloworld]未捕获的异常转义 com.google.gwt.event.shared.UmbrellaException:一个或多个异常被捕获,请参阅UmbrellaException中的完整集#getCauses com.google.gwt.event .shared.HandlerManager.fireEvent(HandlerManager.java:129)在com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)在com.google.gwt .event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)在com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177) at com .google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)

还有更多这样的。 p>

解决方案

com.google.gwt.user.client.Window 类提供对浏览器窗口的方法,属性和事件的访问。所以你不能在Serverside中使用它。当需求满足时,您可以返回String success,否则返回异常,以便它被 onFailure 在客户端。

I have built my first GWT app. giving no compilation errors neither run-time errors. However, when the application is loaded into the browser (using Interner Explorer) and I enter username and password field to validate the user, it throws exceptions. Using GWT-RPC method, entire code and interfaces are provided. I'm using HSQL for database connection(back end).

------------------CODE (CLIENT)

package com.vin.client; 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.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.Label; import com.google.gwt.user.client.ui.PasswordTextBox; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.TextBox; public class HelloWorld implements EntryPoint{ private UserServiceAsync UserService = (UserServiceAsync) GWT.create(UserService.class); public void onModuleLoad() { Button click=new Button("Click Here"); Label name=new Label("Enter Name"); Label passwrd=new Label("Enter Password"); final TextBox t_name=new TextBox(); final PasswordTextBox t_passwrd=new PasswordTextBox(); click.addClickHandler(new ClickHandler() { public void onClick(ClickEvent ev) { String temp_user=t_name.getText(); String temp_pass=t_passwrd.getText(); UserService.loginuser(temp_user, temp_pass, new AsyncCallback<String>() { public void onFailure(Throwable caught) { Window.alert("Please enter valid details"); } public void onSuccess(String result) { Window.alert("Welcome"); // Window.open("127.0.0.1:8888/ExWid.html?gwt.codesvr=127.0.0.1:9997", "Dem", null); } }); } }); RootPanel.get().add(name); RootPanel.get().add(t_name); RootPanel.get().add(passwrd); RootPanel.get().add(t_passwrd); RootPanel.get().add(click); } }

-----------------------------CLIENT INTERFACE (1)

package com.vin.client; import com.google.gwt.user.client.rpc.RemoteService; public interface UserService extends RemoteService { public String loginuser(String username, String password); }

----------------------------CLIENT ASYNC INTERFACE

package com.vin.client; import com.google.gwt.user.client.rpc.AsyncCallback; public interface UserServiceAsync { public void loginuser(String username, String password, AsyncCallback<String> callback); }

--------------------------IMPLEMENTATION OF CLIENT USERSERVICE (SERVER)...DATABASE CONNECTION

package com.vin.server; import java.sql.DriverManager; import java.sql.ResultSet; import com.google.gwt.dev.generator.ast.Statement; import com.google.gwt.user.client.Window; import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.vin.client.UserService; public class UserServiceImpl extends RemoteServiceServlet implements UserService{ private static final long serialVersionUID = 1L; public String loginuser(String username,String password) { try { java.sql.Connection con = null; Class.forName("org.hsqldb.jdbcDriver"); con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/", "SA", ""); Statement st=(Statement) con.createStatement(); ResultSet rs=((java.sql.Statement) st).executeQuery("select username,password from lgfrm"); String user=rs.getString(1); String pass=rs.getString(2); if(username.equals(user) && password.equals(pass)) { Window.alert("success"); } } catch (Exception ae) {} return "success"; } }

------------------THE EXCEPTION LIST WHILE I'M TRYING TO VALIDATE A USER

15:22:54.583 [ERROR] [helloworld] Uncaught exception escaped com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129) at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129) at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116) at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177) at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)

And many more like these.

解决方案

com.google.gwt.user.client.Window class provides access to the browser window's methods, properties, and events. So you can't use it in Serverside. Better you return String "success" when requirement meets, else return Exception, so that it is caught by onFailure on clientside.

更多推荐

运行GWT应用程序时异常

本文发布于:2023-11-27 12:40:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638119.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   异常   GWT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!