gpt4 book ai didi

java - 运行 GWT 应用程序时出现异常

转载 作者:行者123 更新时间:2023-12-02 00:11:28 24 4
gpt4 key购买 nike

我已经构建了我的第一个 GWT 应用程序。没有给出编译错误,也没有给出运行时错误。但是,当应用程序加载到浏览器(使用 Interner Explorer)并且我输入用户名密码字段来验证用户时,它会引发异常。使用GWT-RPC方法,提供了完整的代码和接口(interface)。我使用 HSQL 进行数据库连接(后端)。

------------------代码(客户端)

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("http://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);
}

----------------------------客户端异步接口(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);
}

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

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";
}
}

------------------我尝试验证用户时的异常(exception)列表

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)

还有更多类似的。

最佳答案

com.google.gwt.user.client.Window类提供对浏览器窗口的方法、属性和事件的访问。所以你不能在服务器端使用它。最好在满足要求时返回 String "success" ,否则返回 Exception ,以便客户端的 onFailure 捕获它。

关于java - 运行 GWT 应用程序时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12744112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com