/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.wlin.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.wlin.operatedb.Generate;
import com.wlin.operatedb.OperateDb;
import com.wlin.pojo.User1;
import com.wlin.struts.form.LoginForm;
/**
* MyEclipse Struts
* Creation date: 10-06-2008
*
* XDoclet definition:
* @struts.action path="/login" name="loginForm" input="/index.jsp" parameter="methods" scope="request" validate="true"
*/
public class LoginAction extends DispatchAction {
/*
* Generated Methods
*/
OperateDb db = new OperateDb();
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
//接受用户名和密码
User1 u1= new User1();
String name = loginForm.getRstXm();
String pass = loginForm.getRstMm();
String hql = "from User1 as u1 where u1.name='"+name+"' and u1.password='"+pass+"'";
List list = db.query(hql);
if(list.size()>0){
return new ActionForward("/login.do?methods=query");
}else{
request.setAttribute("info","用户名或密码错误");
return new ActionForward("/index.jsp");
}
}
/**
* 查询数据
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward query(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
User1 u1 = new User1();
String hql = "from User1";
List list = db.query(hql);
if(list!=null||!list.equals("")){
request.setAttribute("palist",list);
}
return new ActionForward("/UserInsert.jsp");
}
/**
* 增加数据
*/
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
Generate tt= new Generate();
String id = tt.generateId();
User1 u1= new User1();
u1.setId(id);
u1.setName(request.getParameter("name"));//姓名
u1.setPassword(request.getParameter("password"));//密码
u1.setQuestion(request.getParameter("question"));//提示问题
u1.setAnswer(request.getParameter("answer"));//问题答案
u1.setEmail(request.getParameter("email"));//E-mail
u1.setState(request.getParameter("state"));//状态
u1.setDiyname(request.getParameter("diyname"));//别名
u1.setMemo(request.getParameter("memo"));//备注
boolean hql = db.insert(u1);
if(hql){
request.setAttribute("info", "保存成功");
}
return new ActionForward("/login.do?methods=query");
}
/*
* 删除数据
*/
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
//获取传递过来的ID值
String id = request.getParameter("id");
//实例话数据库操作类
String sql="delete User1 as us where us.id ='"+id+"'";
boolean hql=db.delete(sql);
if(hql){
request.setAttribute("info", "删除成功");
return new ActionForward("/login.do?methods=query");
}else{
request.setAttribute("info", "删除失败");
return new ActionForward("/index.jsp");
}
}
/**
* 修改数据
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
User1 u1= new User1();
u1.setId(request.getParameter("id"));
u1.setName(request.getParameter("name"));//姓名
u1.setPassword(request.getParameter("password"));//密码
u1.setQuestion(request.getParameter("question"));//提示问题
u1.setAnswer(request.getParameter("answer"));//问题答案
u1.setEmail(request.getParameter("email"));//E-mail
u1.setState(request.getParameter("state"));//状态
u1.setDiyname(request.getParameter("diyname"));//别名
u1.setMemo(request.getParameter("memo"));//备注
boolean hql = db.update(u1);
if(hql){
request.getSession().setAttribute("info", "修改成功");
}
return new ActionForward("/login.do?methods=query");
}
}