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

📄 userregistaction.java

📁 使用J2EE Struts开发的房地产信息咨询系统
💻 JAVA
字号:
/**
 * 处理用户注册处理过程
 * UserResigtAction.java
 * @author usr
 */

package building;

import javax.sql.*;
import javax.servlet.http.*;
import javax.servlet.ServletContext;
import org.apache.struts.action.*;

public final class UserRegistAction extends Action
{
	public ActionForward execute(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response)
	throws Exception
	{
		DynaActionForm userForm = (DynaActionForm)form;
		//提取表单信息
		String userName = (String)userForm.get("username");
		String trueName = (String)userForm.get("truename");
		String password = (String)userForm.get("password");
		String pswNotice = (String)userForm.get("pswnotice");
		String pswItIs = (String)userForm.get("pswitis");
		String sex = (String)userForm.get("sex");
		String birth = (String)userForm.get("birth");
		String tel = (String)userForm.get("tel");
		String email = (String)userForm.get("email");
		String address = (String)userForm.get("address");
		//String signature = (String)userForm.get("signature");
		
		//字体编码
		userName = CharSet.GBK_ISO(userName);
		trueName = CharSet.GBK_ISO(trueName);
		password = CharSet.GBK_ISO(password);
		pswNotice = CharSet.GBK_ISO(pswNotice);
		pswItIs = CharSet.GBK_ISO(pswItIs);
		sex = CharSet.GBK_ISO(sex);
		birth = CharSet.GBK_ISO(birth);
		tel = CharSet.GBK_ISO(tel);
		email = CharSet.GBK_ISO(email);
		address = CharSet.GBK_ISO(address);
		//signature = CharSet.GBK_ISO(signature);
		
		//
		password = MD5.comuteDigest(password);
		
		//填充Java Bean
		Users user = new Users();
		
		user.setUserName(userName);
		user.setTrueName(trueName);
		user.setPassword(password);
		user.setPswNotice(pswNotice);
		user.setPswItIs(pswItIs);
		user.setSex(sex);
		user.setBirth(birth);
		user.setTel(tel);
		user.setEmail(email);
		user.setAddress(address);
		//
		
		//数据库连接
		ServletContext context = servlet.getServletContext();
		DataSource dataSource = (DataSource)context.getAttribute(Constants.DATASOURCE_KEY);
		DB db = new DB(dataSource);
		
		//页面跳转
		String PageForward = null;
		
		//错误处理
		ActionMessages errors = new ActionMessages();
		
		//检查是否已经有该用户名注册
		if ( Users.ifExist(db,userName) )
		{
			//此用户名已经存在			
			errors.add(ActionMessages.GLOBAL_MESSAGE,
					new ActionMessage("errors.userAlreadyExist"));
			if (!errors.isEmpty())
			{
				saveErrors(request,errors);
			}//End of if
			
			PageForward = "toWrong";
		}//End of if
		else
		{
			//用户名没被占用
			//进行添加操作
			if ( user.addUser(db) )
			{
				//添加成功
				PageForward = "toUserRegistOK";
			}//End of if
			else
			{
				//添加失败
				errors.add(ActionMessages.GLOBAL_MESSAGE,
						new ActionMessage("errors.addUserFail"));
				if (!errors.isEmpty())
				{
					saveErrors(request,errors);
				}//End of if
				
				PageForward = "toWrong";
			}//End of else
			 
		}//End of else
		
		//关闭数据库连接
		db.close();
		
		//换会跳转页面
		return(mapping.findForward(PageForward));
	}//End of execute
	
}//End of class UserRegistAction

⌨️ 快捷键说明

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