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

📄 cellphoneeditaction.java

📁 这个是完整的wap项目的源码 开发语言 Java 系统架构 Struts + hibernate + spring 数据库 Mysql5.0 应用服务器Tomcat5.0 开发工具 MyEc
💻 JAVA
字号:
package com.longtime.wap.module.cellphone.web.action;

import java.util.ArrayList;
import java.util.List;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.DispatchActionSupport;

import com.longtime.wap.common.WapConstant;
import com.longtime.wap.model.Cellphone;
import com.longtime.wap.module.cellphone.service.CellphoneService;
import com.longtime.wap.module.cellphone.web.form.CellphoneForm;

/**
 * 处理修改请求
 * 
 * @author shiz
 * @date Nov 19, 2007
 */
public class CellphoneEditAction extends DispatchActionSupport {
	private static final Log LOGGER = 
		LogFactory.getLog(CellphoneEditAction.class);
	private CellphoneService cellphoneService;

	/**
	 * 注入服务对象
	 * 
	 * @param cellphoneService
	 *            设置服务对象
	 */
	public void setCellphoneService(CellphoneService cellphoneService) {
		this.cellphoneService = cellphoneService;
	}

	/**
	 * 获得相应手机信息
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param form
	 *            ActionForm对象
	 * @param request
	 *            HttpServletRequest对象
	 * @param response
	 *            HttpServletResponse对象
	 * @return ActionForward对象
	 * @throws Exception
	 *             异常处理
	 */
	public ActionForward getCellphone(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Cellphone cellphone = null;
		String type = request.getParameter("type");
		// 设置返回的formbean对象
		CellphoneForm cellphoneForm = (CellphoneForm) form;
		String cellphoneId = request.getParameter("id");
		try {
			// 根据Id取information
			if (null != cellphoneId) {
				cellphone = cellphoneService.getCellphoneById(Long
						.parseLong(cellphoneId));
				cellphoneForm.setCellphoneId(String.valueOf(cellphone
						.getCellphoneId()));
				cellphoneForm.setCellphoneUA(String.valueOf(cellphone.getUa()));
				cellphoneForm.setCellphoneType(String.valueOf(cellphone
						.getModel()));
				cellphoneForm.setCellphoneCompany(String.valueOf(cellphone
						.getBrand()));
				cellphoneForm.setUniqueUa(String.valueOf(cellphone.getUa()));
				cellphoneForm.setUniqueType(String
						.valueOf(cellphone.getModel()));
				if ("view".equalsIgnoreCase(type)) {
					String imageType = "";
					if (cellphone.getSupportImageType() == 0) {
						imageType = "Png";
					} else if (cellphone.getSupportImageType() == 1) {
						imageType = "Jpg";
					} else if (cellphone.getSupportImageType() == 2) {
						imageType = "Bmp";
					} else {
						imageType = "Gif";
					}
					cellphoneForm.setCellphonePicture(imageType);
				} else {
					cellphoneForm.setCellphonePicture(String.valueOf(cellphone
							.getSupportImageType()));
				}
				request.setAttribute("cellphoneForm", cellphoneForm);
			}
			// 设置返回页面是否允许编辑
			if ("edit".equalsIgnoreCase(type)) {
				cellphoneForm.setEditFlug("edit");
			}
			if ("view".equalsIgnoreCase(type)) {
				cellphoneForm.setEditFlug("view");
			}
			if ("new".equalsIgnoreCase(type)) {
				cellphoneForm.setEditFlug("new");
			}

		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
		return mapping.findForward("detailCellphone");
	}

	/**
	 * 处理新增或修改中的保存请求
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param form
	 *            ActionForm对象
	 * @param request
	 *            HttpServletRequest对象
	 * @param response
	 *            HttpServletResponse对象
	 * @return ActionForward对象
	 * @throws Exception
	 *             异常对象
	 */
	public ActionForward saveCellphone(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<String> messages = new ArrayList<String>();
		try {
			CellphoneForm cellphoneForm = (CellphoneForm) form;
			String flug = cellphoneForm.getEditFlug();
			String ua = cellphoneForm.getCellphoneUA().trim();
			String model = cellphoneForm.getCellphoneType().trim();
			Cellphone cellphone;
			if (flug.equals("new")) {
				// 增加
				cellphone = new Cellphone();
				if (null == cellphoneService.getCellphoneByUA(ua)) {
					if (null == cellphoneService.getCellphoneByModel(model)) {
						cellphone.setUa(cellphoneForm.getCellphoneUA().trim());
						cellphone.setModel(cellphoneForm.getCellphoneType()
								.trim());
						cellphone.setBrand(cellphoneForm.getCellphoneCompany()
								.trim());
						cellphone.setSupportImageType(Long
								.parseLong(cellphoneForm.getCellphonePicture()
										.trim()));
						cellphoneService.saveCellphone(cellphone);
						messages.add("手机信息保存成功!");
					} else {
						messages.add("手机型号已经存在!");
						request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES,
								messages);
						return mapping.findForward("failed");
					}
				} else {
					messages.add("手机UA已经存在!");
					request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES,
							messages);
					return mapping.findForward("failed");
				}
			} else if (flug.equals("edit")) {
				// 修改
				cellphone = cellphoneService.getCellphoneById(Long
						.parseLong(cellphoneForm.getCellphoneId()));
				if (null != cellphoneForm.getCellphoneId()
						&& cellphoneForm.getCellphoneId().length() > 0) {
					if (cellphoneForm.getUniqueUa().equals(ua)
							|| (null == cellphoneService.getCellphoneByUA(ua))) 
					{
						cellphone.setUa(cellphoneForm.getCellphoneUA().trim());
					} else {
						messages.add("手机UA已经存在!");
						request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES,
								messages);
						return mapping.findForward("failed");
					}
					if (cellphoneForm.getUniqueType().equals(model)
							|| (null == cellphoneService
									.getCellphoneByModel(model))) {
						cellphone.setModel(cellphoneForm.getCellphoneType()
								.trim());
					} else {
						messages.add("手机型号已经存在!");
						request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES,
								messages);
						return mapping.findForward("failed");
					}
					cellphone.setBrand(cellphoneForm.getCellphoneCompany()
							.trim());
					cellphone.setSupportImageType(Long.parseLong(cellphoneForm
							.getCellphonePicture().trim()));
					cellphoneService.saveCellphone(cellphone);
					messages.add("手机信息修改成功!");
				} else {
					messages.add("没有此手机信息");
				}
			}
		} catch (Exception ex) {
			LOGGER.error(ex);
			messages.add("手机信息保存失败");
			ex.printStackTrace();
		}
		request.setAttribute(WapConstant.WAP_GLOBAL_MESSAGES, messages);
		return mapping.findForward("cellphones");

	}
}

⌨️ 快捷键说明

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