⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regform.java

📁 是一个网站的博客系统
💻 JAVA
字号:
package com.opensource.blog.web.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.laoer.comm.util.Util;
import com.opensource.blog.comm.BlogUtil;
import com.opensource.blog.comm.Constant;

public class RegForm
    extends ActionForm {

  private String action;
  private String address;
  private int age;
  private String answer;
  private String blogname;
  private int cansee;
  private String city;
  private String description;
  private int edulevel;
  private String email;
  private int income;
  private int industry;
  private String mb;
  private String nickname;
  private String passwd;
  private String passwdre;
  private int pro;
  private String question;
  private int sex;
  private int skin;
  private int sort;
  private String username;
  private int work;

  public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
    ActionErrors errors = new ActionErrors();

    httpServletRequest.setAttribute("canseeValues", Constant.YESORNOS);
    httpServletRequest.setAttribute("ageValues", Constant.AGES);
    httpServletRequest.setAttribute("proValues", Constant.PROS);
    httpServletRequest.setAttribute("workValues", Constant.WORKS);
    httpServletRequest.setAttribute("incomeValues", Constant.INCOMES);
    httpServletRequest.setAttribute("sortValues", Constant.SORTS);
    httpServletRequest.setAttribute("industryValues", Constant.INDUSTRYS);
    httpServletRequest.setAttribute("edulevelValues", Constant.EDULEVELS);

    if (StringUtils.isBlank(this.action)) {
      this.action = "new";
    }

    if (this.action.equalsIgnoreCase("add")) {

      if (StringUtils.isBlank(username) || StringUtils.isBlank(nickname) ||
          StringUtils.isBlank(passwd) || StringUtils.isBlank(passwdre) ||
          StringUtils.isBlank(question) || StringUtils.isBlank(answer) || StringUtils.isBlank(email) ||
          StringUtils.isBlank(blogname) || StringUtils.isBlank(description)) {
        errors.add("error.nullerror", new ActionMessage("error.nullerror"));

      }
      username = username.trim();
      if (!StringUtils.isAlphanumeric(username)) {
        errors.add("error.reg.username1", new ActionMessage("error.reg.username1"));
      }

      if (username.length() < 3 || username.length() > 20) {
        errors.add("error.reg.username0", new ActionMessage("error.reg.username0"));
      }

      if (!StringUtils.isAlphanumeric(passwd)) {
        errors.add("error.reg.passwd2", new ActionMessage("error.reg.passwd2"));
      }
      if (passwd.length() < 3 || passwd.length() > 25) {
        errors.add("error.reg.passwd0", new ActionMessage("error.reg.passwd0"));
      }
      if (!passwd.equals(passwdre)) {
        errors.add("error.reg.passwd1", new ActionMessage("error.reg.passwd1"));
      }
      passwdre = Util.hash(passwd);

      nickname = nickname.trim();
      question = question.trim();
      answer = answer.trim();
      email = email.trim();
      blogname = blogname.trim();
      description = description.trim();

      if (BlogUtil.getStringLength(nickname) == 0 || BlogUtil.getStringLength(nickname) > 20) {
        errors.add("error.reg.nickname", new ActionMessage("error.reg.nickname"));
      }
      if (BlogUtil.getStringLength(question) > 100) {
        errors.add("error.reg.question", new ActionMessage("error.reg.question"));
      }
      if (BlogUtil.getStringLength(answer) > 100) {
        errors.add("error.reg.answer", new ActionMessage("error.reg.answer"));
      }
      if (BlogUtil.getStringLength(blogname) > 60) {
        errors.add("error.reg.blogname", new ActionMessage("error.reg.blogname"));
      }
      if (BlogUtil.getStringLength(description) > 600) {
        errors.add("error.reg.blogdesp", new ActionMessage("error.reg.blogdesp"));
      }

      if (age == 0) {
        errors.add("error.reg.age", new ActionMessage("error.reg.age"));
      }
      if (pro == 0) {
        errors.add("error.reg.pro", new ActionMessage("error.reg.pro"));
      }
      if (work == 0) {
        errors.add("error.reg.work", new ActionMessage("error.reg.work"));
      }
      if (income == 0) {
        errors.add("error.reg.income", new ActionMessage("error.reg.income"));
      }

      if (industry == 0) {
        errors.add("error.reg.industry", new ActionMessage("error.reg.industry"));
      }
      if (edulevel == 0) {
        errors.add("error.reg.edulevel", new ActionMessage("error.reg.edulevel"));
      }
      if (city == null) {
        city = "";
      }
      if (mb == null) {
        mb = "";
      }
      if (address == null) {
        address = "";
      }
    }
    return errors;
  }

  public void reset(ActionMapping actionMapping, HttpServletRequest servletRequest) {
  }

  public String getAddress() {
    return address;
  }

  public int getAge() {
    return age;
  }

  public String getAnswer() {
    return answer;
  }

  public String getBlogname() {
    return blogname;
  }

  public int getCansee() {
    return cansee;
  }

  public String getCity() {
    return city;
  }

  public String getDescription() {
    return description;
  }

  public int getEdulevel() {
    return edulevel;
  }

  public String getEmail() {
    return email;
  }

  public int getIncome() {
    return income;
  }

  public int getIndustry() {
    return industry;
  }

  public String getMb() {
    return mb;
  }

  public String getNickname() {
    return nickname;
  }

  public String getPasswd() {
    return passwd;
  }

  public String getPasswdre() {
    return passwdre;
  }

  public int getPro() {
    return pro;
  }

  public String getQuestion() {
    return question;
  }

  public int getSex() {
    return sex;
  }

  public int getSkin() {
    return skin;
  }

  public int getSort() {
    return sort;
  }

  public String getUsername() {
    return username;
  }

  public int getWork() {
    return work;
  }

  public String getAction() {
    return action;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public void setAge(int age) {
    this.age = age;
  }

  public void setAnswer(String answer) {
    this.answer = answer;
  }

  public void setBlogname(String blogname) {
    this.blogname = blogname;
  }

  public void setCansee(int cansee) {
    this.cansee = cansee;
  }

  public void setCity(String city) {
    this.city = city;
  }

  public void setDescription(String description) {
    this.description = description;
  }

  public void setEdulevel(int edulevel) {
    this.edulevel = edulevel;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public void setIncome(int income) {
    this.income = income;
  }

  public void setIndustry(int industry) {
    this.industry = industry;
  }

  public void setMb(String mb) {
    this.mb = mb;
  }

  public void setNickname(String nickname) {
    this.nickname = nickname;
  }

  public void setPasswd(String passwd) {
    this.passwd = passwd;
  }

  public void setPasswdre(String passwdre) {
    this.passwdre = passwdre;
  }

  public void setPro(int pro) {
    this.pro = pro;
  }

  public void setQuestion(String question) {
    this.question = question;
  }

  public void setSex(int sex) {
    this.sex = sex;
  }

  public void setSkin(int skin) {
    this.skin = skin;
  }

  public void setSort(int sort) {
    this.sort = sort;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public void setWork(int work) {
    this.work = work;
  }

  public void setAction(String action) {
    this.action = action;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -