customeraction.java

来自「加拿大达内科技有限公司配需java程序员的上课时的代码」· Java 代码 · 共 55 行

JAVA
55
字号
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package actions;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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 service.CustomerService;
import entity.Customer;
import forms.CustomerForm;

/** 
 * MyEclipse Struts
 * Creation date: 11-10-2008
 * 
 * XDoclet definition:
 * @struts.action path="/customer" name="customerForm" input="/add_customer.jsp" scope="request"
 * @struts.action-forward name="list" path="/list_customers.jsp"
 */
public class CustomerAction extends Action {
	private CustomerService cs;
	
	/*
	 * Generated Methods
	 */

	public void setCs(CustomerService cs) {
		this.cs = cs;
	}

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		CustomerForm customerForm = (CustomerForm) form;// TODO Auto-generated method stub
		Customer c = new Customer();
		c.setName(customerForm.getName());
		c.setAge(Integer.parseInt(customerForm.getAge()));
		cs.addCustomer(c);
		request.setAttribute("customers", cs.listAll());
		return mapping.findForward("list");
	}
}

⌨️ 快捷键说明

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