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

📄 registeraction.java

📁 Italk吧简易论坛 基于struts+extjs+hibernate+spring+mysql开发。 /catch目录为系统截图 安装步骤: 1:安装MYSQL
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.italk.action;

import java.io.File;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.italk.vo.AdvanceInfo;
import com.italk.vo.BaseInfo;
import com.italk.vo.User;
import com.italk.util.StringUtil;

/**
 * MyEclipse Struts Creation date: 11-13-2008
 * 
 * XDoclet definition:
 * 
 * @struts.action validate="true"
 */
public class RegisterAction extends BaseAction {
	/*
	 * Generated Methods
	 */

	/**
	 * Method execute
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		try {
			DiskFileItemFactory factory = new DiskFileItemFactory();
			factory.setSizeThreshold(0x80000);
			String temppath = request.getSession().getServletContext()
					.getRealPath("/");
			temppath = temppath + "/WEB-INF/upload/";
			File file = new File(temppath);
			factory.setRepository(file);
			ServletFileUpload upload = new ServletFileUpload(factory);
			upload.setHeaderEncoding("UTF-8");
			List itemsList = upload.parseRequest(request);
			Iterator items = itemsList.iterator();

			log.debug("getParamter->userName="
					+ request.getParameter("userName"));
			byte[] photo = null;
			String password = null;
			String sex = null;
			String email = null;
			String age = null;
			String realName = null;
			String nickName = null;
			String phone = null;
			String qq = null;
			String description = null;
			String website = null;
			String born = null;
			String userName = null;
			log.debug(items.hasNext() + "");
			while (items.hasNext()) {
				log.debug("9");
				FileItem item = (FileItem) items.next();
				if (!item.isFormField()) {
					log.debug("10");
					log.debug("fieldName:" + item.getFieldName());
					log.debug("name:" + item.getName());
					log.debug("size:" + item.getSize());
					log.debug("contentType:" + item.getContentType());
					log.debug("isInMemory:" + item.isInMemory());
					photo = item.get();
					log.debug("photo:" + photo.length);
				} else {
					log.debug("begin get paramter");
					String fieldName = item.getFieldName();
					if (fieldName.equals("userName")) {
						userName = item.getString();
						log.debug("userName:" + userName);
					} else if (fieldName.equals("password")) {
						password = item.getString("UTF-8");
						log.debug("password:" + password);
					} else if (fieldName.equals("sex")) {
						sex = item.getString();
						log.debug("sex:" + sex);
					} else if (fieldName.equals("email")) {
						email = item.getString();
						log.debug("email:" + email);
					} else if (fieldName.equals("age")) {
						age = item.getString();
						log.debug("age:" + age);
					} else if (fieldName.equals("realName")) {
						realName = item.getString("UTF-8");
						log.debug("realName:" + realName);
					} else if (fieldName.equals("nickName")) {
						nickName = item.getString("UTF-8");
						log.debug("nickName:" + nickName);
					} else if (fieldName.equals("phone")) {
						phone = item.getString();
						log.debug("phone:" + phone);
					} else if (fieldName.equals("qq")) {
						qq = item.getString();
						log.debug("qq:" + qq);
					} else if (fieldName.equals("description")) {
						description = item.getString("UTF-8");
						log.debug("description:" + description);
					} else if (fieldName.equals("website")) {
						website = item.getString();
						log.debug("website:" + website);
					} else if (fieldName.equals("born")) {
						born = item.getString();
						log.debug("born:" + born);
					}
				}
			}
			BaseInfo bi = new BaseInfo();
			AdvanceInfo ai = new AdvanceInfo();

			bi.setUserName(userName);
			bi.setPassword(password);
			bi.setEmail(email);
			bi.setSex(new Character(sex.charAt(0)));

			if (age != null && age.length() > 0) {
				ai.setAge(Integer.decode(age));
			}
			ai.setRealName(realName);
			ai.setNickName(nickName);
			ai.setWebsite(website);
			ai.setPhoto(photo);
			if (born != null && born.length() > 0) {
				ai.setBorn(StringUtil.bornToLong(born));
			} else {
				ai.setBorn(null);
			}
			ai.setPhone(phone);
			ai.setQq(qq);
			ai.setDescription(description);

			User u = new User();
			u.setBaseInfo(bi);
			u.setAdvanceInfo(ai);

			boolean result = userService.register(u);
			log.info("user register");
			response.setContentType("text/xml");
			PrintWriter out = response.getWriter();
			out.print("<results><result>" + result + "</result></results>");
			out.flush();
			out.close();
		} catch (Exception e) {
			log.error("register page error", e);
		}
		return null;
	}
}

⌨️ 快捷键说明

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