useraction.java

来自「基于SSH的实现用户注册与登入功能。非常适合SSH初学者的入门。其中的设计模式可」· Java 代码 · 共 58 行

JAVA
58
字号
package com.yuanchung.test.users.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
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.yuanchung.test.exception.*;
import com.yuanchung.test.service.users.usersMgr;
import com.yuanchung.struts.form.LoginForm;
import com.yuanchung.test.util.CONSTANTS;

public class UserAction extends DispatchAction {
	private static Logger logger = Logger.getLogger(UserAction.class);
	private usersMgr userMgr;

	public usersMgr getUserMgr() {
		return userMgr;
	}

	public void setUserMgr(usersMgr userMgr) {
		this.userMgr = userMgr;
	}

	public ActionForward register(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws myException {
		System.out.println("ddddddddddddddd");
		response.setCharacterEncoding("utf-8");
		LoginForm userform = (LoginForm) form;
		String forward = null;
		String username = userform.getUsername();
		String userNameddd = request.getParameter("username");
		System.out.println("kkkkkkkkkkkkkkkkkkk:"+userNameddd);
		System.out.println("---rrrrr-----"+username);
		String password = userform.getPassword().trim();
		System.out.println("-----ggg---"+password);
		String repassword = request.getParameter("repassword").trim();
		logger.debug("Test Log:");
		try {
			forward="failure";
			if (!password.equals(repassword)) {
				forward = "failure";
				throw new myException(CONSTANTS.REGISTERPASSWORDERROR);
			} else {
				forward = "success";
				userMgr.registerUser(username, password);

			}
		} catch (myException e) {
			e.printStackTrace();
			forward="failure";
			request.setAttribute("registerInfo", e.getMessage());
		}
		return mapping.findForward(forward);
	}
}

⌨️ 快捷键说明

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