UserAddAction.java~36~
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:3k
源码类别:
OA系统
开发平台:
Java
- package officeol.mc.actions;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionForm;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.Action;
- import officeol.mc.tools.*;
- public class UserAddAction extends Action {
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- try {
- request.setCharacterEncoding("GBK");
- DBConn dbc = new DBConn();
- Tool tl = new Tool();
- String un = StringFilter.filter(tl.isNull(request.getParameter(
- "username").trim()));
- String pwd = StringFilter.filter(tl.isNull(request.getParameter(
- "pwd").trim()));
- String pwd1 = StringFilter.filter(tl.isNull(request.getParameter(
- "pwd2").trim()));
- String dep = "0";
- String xm = request.getParameter("xm");
- String sex = request.getParameter("sex");
- String tel = request.getParameter("tel");
- String tel2 = request.getParameter("tel2");
- String email = request.getParameter("email");
- if (un != null && pwd != null && pwd1 != null && dep != null) {
- String checksql = "select * from [user] where username = '" +
- un +
- "' ";
- String[][] checkun = dbc.getArray(checksql);
- if (checkun == null) {
- if (pwd.equals(pwd1)) {
- String unmd5 = tl.hash(un);
- String pwdmd5 = tl.hash(pwd);
- String sql =
- "insert into [user] (username,password,deparment,unmd5,xingming,sex,tel,tel2,email) values" +
- "('" + un + "','" + pwdmd5 + "'," + dep + ",'"+
- unmd5+"','"+xm+"','"+sex+"','"+tel+"','"+tel2+"','"+email+"')";
- //System.out.println(sql);
- dbc.executeUpdate(sql);
- request.setAttribute("msg",
- "用户" + un + "添加成功!密码为" + pwd +" ");
- return mapping.findForward("succ");
- } else {
- request.setAttribute("msg", "再次输入密码不相同,请重新输入!");
- return mapping.findForward("err");
- }
- } else {
- request.setAttribute("msg", "用户名 " + un + " 已经注册过,请用其他用户名!");
- return mapping.findForward("err");
- }
- } else {
- request.setAttribute("msg", "用户名,密码,部门不允许为空!");
- return mapping.findForward("err");
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- request.setAttribute("msg", "注册发生异常,请重试!");
- }
- return mapping.findForward("err");
- }
- }