Java 运行在Glass Fish服务器上的Web服务上的Netbeans中的FileNotFoundException
当在GUI上单击该按钮时,此事件处理程序将被激活。实现声明的 @在课堂上使用WebMethodJava 运行在Glass Fish服务器上的Web服务上的Netbeans中的FileNotFoundException,java,web-services,serialization,netbeans,filenotfoundexception,Java,Web Services,Serialization,Netbeans,Filenotfoundexception,当在GUI上单击该按钮时,此事件处理程序将被激活。实现声明的 @在课堂上使用WebMethod private void btn_loginActionPerformed(java.awt.event.ActionEvent evt) { int result; String username = us_textField.getText(); String password = ne
private void btn_loginActionPerformed(java.awt.event.ActionEvent evt) {
int result;
String username = us_textField.getText();
String password = new String(pw_textField.getPassword());
try {
result = employeeLogin(username, password);
} catch (IOException_Exception ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
result = 0;
} catch (FileNotFoundException_Exception ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
result = 0;
} catch (ClassNotFoundException_Exception ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
result = 0;
}
if (result == 0) {
lbl_loginStatus.setText("Invalid Inputs");
} else if (result == 1) {
lbl_loginStatus.setText("Username and password does not match!");
} else {
lbl_loginStatus.setText("Login Successful!");
new Choose().setVisible(true);
this.dispose();
}
}
这是在同一类中声明web服务的方式
private static int employeeLogin(java.lang.String username, java.lang.String password) throws IOException_Exception, FileNotFoundException_Exception, ClassNotFoundException_Exception {
ws_employee.CWWsEmployee_Service service = new ws_employee.CWWsEmployee_Service();
ws_employee.CWWsEmployee port = service.getCWWsEmployeePort();
return port.employeeLogin(username, password);
}
这是Web服务代码
EmployeeMainController controller = new EmployeeMainController();
@WebMethod(operationName = "EmployeeLogin")
public int EmployeeLogin(@WebParam(name = "username") String username, @WebParam(name = "password") String password) throws IOException, FileNotFoundException, ClassNotFoundException {
//TODO write your implementation code here:
return controller.EmployeeLogin(username, password);
}
这是EmployeeMainController.java
类中声明的EmployeeLogin(用户名、密码)
方法。在此方法中,由LoadData()
方法初始化的ArrayList
public int EmployeeLogin(String username, String password) throws FileNotFoundException, IOException, ClassNotFoundException {
// Loading to the array list from the text file.
ArrayList<EmployeeStruct> loadArray = new ArrayList<EmployeeStruct>();
loadArray = LoadList();
for (EmployeeStruct val : loadArray) {
if (val.getEmpUsername().equals(username) && val.getEmpPassword().equals(password)) {
return 2;
} else if (val.getEmpUsername().equals(username) || val.getEmpPassword().equals(password)) {
return 1;
}
}
return 0;
}
但是当执行代码时,ws_employee.FileNotFoundException\u Exception:cw_employeeData.txt(系统找不到指定的文件).
控制台中出现错误
甚至我也在根目录中的root/src
文件夹旁边找到了cw_employeeData.txt
文件
public ArrayList<EmployeeStruct> LoadList() throws FileNotFoundException, IOException, ClassNotFoundException {
ArrayList<EmployeeStruct> employeeList = new ArrayList<EmployeeStruct>();
File file = new File(filename);
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
try {
while (true) {
EmployeeStruct x = (EmployeeStruct) ois.readObject();
// System.out.println(x.toString());
employeeList.add(x);
}
} catch (EOFException e) {
// TODO Auto-generated catch block
System.out.println("Completed reading from the file " + filename);
}
// employeeList.add(admin);
return employeeList;
}