webservice06#异常
1, 异常处理
package com.yangw.soap.service; public class UserException extends Exception { public UserException() { super(); } public UserException(String message, Throwable cause) { super(message, cause); } public UserException(String message) { super(message); } public UserException(Throwable cause) { super(cause); } }
为login()方法增加抛异常
package com.yangw.soap.service; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; //说明该接口是服务接口 @WebService public interface IMyService { ...... @WebResult(name="user") public User login(@WebParam(name="username")String username, @WebParam(name="password")String password) throws UserException;
...... }
package com.yangw.soap.service; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.jws.WebService; //说明该类是服务接口的实现类 @WebService(endpointInterface="com.yangw.soap.service.IMyService") public class MyServiceImpl implements IMyService { ...... @Override public User login(String username, String password) throws UserException{ for(User user:users){ if(user.getUserName().equals(username)&&user.getPassword().equals(password)){ return user; } } throw new UserException("用户不存在!"); } ...... }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。