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

📄 informationdetailaction.java

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

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.commons.validator.GenericValidator;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.longtime.wap.common.WapConstant;
import com.longtime.wap.common.enums.CategoryEnum;
import com.longtime.wap.frame.common.UserSessionVO;
import com.longtime.wap.model.Information;
import com.longtime.wap.model.Payment;
import com.longtime.wap.model.UserInfo;
import com.longtime.wap.module.front.common.FrontConstant;
import com.longtime.wap.module.front.service.FrontService;
import com.longtime.wap.module.front.web.form.InformationDetailForm;

/**
 * 处理详细信息请求
 * 
 * @author bulc
 * @date Nov 19, 2007
 */
public class InformationDetailAction extends FrontBaseAction {
	private static final Log LOGGER = LogFactory
			.getLog(InformationDetailAction.class);

	private FrontService frontService;

	/**
	 * 注入服务对象
	 * 
	 * @param frontService
	 *            服务对象
	 */
	public void setFrontService(FrontService frontService) {
		this.frontService = frontService;
	}

	/**
	 * 获取信息请求处理
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param form
	 *            ActionForm对象
	 * @param request
	 *            HttpServletRequest对象
	 * @param response
	 *            HttpServletResponse对象
	 * @return ActionForward对象
	 * @throws Exception
	 *             异常对象
	 */
	public ActionForward getInformation(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		if (!this.isUser(request)) {
			// 禁止访问页面信息
			return mapping.findForward("error");
		} else {
			// 正常访问
			try {
				UserSessionVO usVo = (UserSessionVO) request.getSession()
						.getAttribute(WapConstant.USER_SESSION);
				long userId = usVo.getUserId();
				long infoId = Long.parseLong(request.getParameter("id"));
				Information info = super.filtInformationContent(frontService
						.getInfoById(infoId), frontService);
				if (null == info) {
					throw new RuntimeException("您所查看的信息不存在");
				}
				InformationDetailForm idForm = new InformationDetailForm();
				idForm
						.setInformationId(String.valueOf(info
								.getInformationId()));
				idForm.setTitle(info.getTitle());
				idForm.setCpName(info.getBusiness().getCp().getCompanyName());
				idForm.setCategory(String.valueOf(info.getBusiness()
						.getCategory()));
				idForm.setCategoryName(CategoryEnum.getValue(
						info.getBusiness().getCategory()).toChinese());
				Payment payment = frontService.getPaymentByUserIdAndInfoId(
						userId, infoId);
				if (null != payment) {
					// 买过
					idForm.setContent(info.getContent());
					if (!GenericValidator.isBlankOrNull(info.getFilePath())) {
						idForm.setFilePath(info.getFilePath());
					}
					idForm.setDetailFlug("detail");
				} else {
					// 没买过
					idForm
							.setBusinessName(info.getBusiness()
									.getBusinessName());
					idForm.setPrice(String.valueOf(info.getPrice()));
					idForm.setDetailFlug("temp");
				}
				request.setAttribute(FrontConstant.INFORMATION_DETAIL_FORM,
						idForm);
			} catch (Exception ex) {
				LOGGER.error(ex);
				ex.printStackTrace();
			}
			super.setHeader(request, frontService);
			super.setLeft(request, frontService);
			return mapping.findForward("infoDetail");
		}

	}

	/**
	 * 购买信息请求处理
	 * 
	 * @param mapping
	 *            ActionMapping对象
	 * @param form
	 *            ActionForm对象
	 * @param request
	 *            HttpServletRequest对象
	 * @param response
	 *            HttpServletResponse对象
	 * @return ActionForward对象
	 * @throws Exception
	 *             异常对象
	 */
	public ActionForward buyInformation(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			InformationDetailForm idForm = (InformationDetailForm) form;
			UserSessionVO usVo = (UserSessionVO) request.getSession()
					.getAttribute(WapConstant.USER_SESSION);
			long userId = usVo.getUserId();
			long infoId = Long.parseLong(request.getParameter("id"));
			frontService.savePurchaseInfo(userId, infoId);
			// 更新显示用户的余额
			UserInfo user = frontService.getUserById(userId);
			usVo.setMoney(String.valueOf(user.getMoney()));
			Information info = this.filtInformationContent(frontService
					.getInfoById(infoId), frontService);
			idForm.setContent(info.getContent());
			if (!GenericValidator.isBlankOrNull(info.getFilePath())) {
				idForm.setFilePath(info.getFilePath());
			}
			idForm.setDetailFlug("detail");
		} catch (RuntimeException ex) {
			request.setAttribute(FrontConstant.BUY_INFO_ERROR, ex.getMessage());
		} catch (Exception ex) {
			LOGGER.error(ex);
			ex.printStackTrace();
		}
		super.setHeader(request, frontService);
		super.setLeft(request, frontService);
		return mapping.findForward("infoDetail");
	}
}

⌨️ 快捷键说明

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