📄 productaddaction.java
字号:
/*
* Created on 2005-12-3
* Author 曹汕
* Version 1.0
* Copyright by CS.SSPKU Inc. All rights reserved.
*/
package com.struts.action;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import com.struts.business.Product;
import com.struts.utils.Constants;
/**
* @author cs
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ProductAddAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaActionForm registerForm = (DynaActionForm) form;
String product_name = (String) registerForm.get("product_name");
String product_code = (String) registerForm.get("product_code");
Double standard_price = (Double) registerForm.get("standard_price");
String barcode = (String) registerForm.get("barcode");
Integer product_type_id = (Integer) registerForm.get("product_type_id");
String pic_url = (String) registerForm.get("pic_url");
String description = (String) registerForm.get("description");
Double member_price = (Double) registerForm.get("member_price");
Integer quantity = (Integer) registerForm.get("quantity");
Product product=new Product();
product.setName(product_name);
product.setCode(product_code);
product.setStandard_price(standard_price.floatValue());
product.setBarcode(barcode);
product.setPic_url(pic_url);
product.setProduct_type(product_type_id.intValue());
product.setStock_quantity(quantity.intValue());
product.setMember_price(member_price.floatValue());
product.setDescription(description);
ServletContext context = servlet.getServletContext();
String PageForward = null;
ActionMessages errors = new ActionMessages();
//获取session
HttpSession session = request.getSession(true);
/**
* 产品新增成功操作后相应的action
*/
if(true){
PageForward = "toIndex";
}
else {
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("errors.addProductInsertFailed"));
if (!errors.isEmpty()) saveErrors(request, errors);
PageForward="toWrong";
}
return mapping.findForward(PageForward);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -