判断登陆的类:
public boolean index1(String userid,String password){
DBcon dbcon=new DBcon();
String sql="select * from yhid where yhid='"+userid+"' and yhpassword='"+password+"'";
try {
Statement stmt = dbcon.getcon().createStatement();
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
System.out.println("访问数据库成功");
return true;
} else {
System.out.println("访问数据库失败");
return false;
}
} catch (Exception ex) {
System.out.println("出现SELECTCLASS里异常");
return false;
}
}
进行删除的类
public boolean del(String userid){
DBcon dbcon=new DBcon();
String sql="delete from yhid where yhid='"+userid+"'";
try {
Statement stmt = dbcon.getcon().createStatement();
int i = stmt.executeUpdate(sql);
if (i > 0) {
System.out.println("DELETECLASS删除成功");
return true;
} else {
System.out.println("DELETECLASS删除失败");
return false;
}
} catch (SQLException ex) {
System.out.println("DELETECLASS删除出现异常");
return false;
}
}
判断登陆的ACTION
public class Untitled1Action extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
HttpSession session=request.getSession();
Untitled1ActionForm f = (Untitled1ActionForm) form;
String userid=f.getUserid();
String password=f.getPassword();
SelectClass sc=new SelectClass();
boolean i=sc.index1(userid,password);
if(i){
System.out.println("I为真");
session.setAttribute("userid",userid);
return mapping.findForward("welcome");
}
else{
System.out.println("I为假");
return mapping.findForward("error");
}
}
输出的ACTION
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
Untitled2ActionForm f= (Untitled2ActionForm) form;
String userid=f.getUserid();
DeleteClass dc=new DeleteClass();
boolean i=dc.del(userid);
if(i){
System.out.println("成功删除");
return mapping.findForward("delok");
}
else{
System.out.println("删除失败");
return mapping.findForward("error1");
}
用两个ACTIONFORM分别加ACTION做的,注意的是删除的判断是用一个整数来表示所改变的行数来判断.