import org.apache.struts.actions.DispatchAction;
import org.apache.commons.beanutils.*;
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.moto.struts.action;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.commons.beanutils.*;
import com.moto.dao.Operate;
import com.moto.struts.form.CustomerForm;
import com.moto.vo.clienter.ClientBusiness;
import com.moto.vo.clienter.ClientBusinessInfo;
import com.moto.vo.clienter.ClientInfo;
import com.moto.vo.clienter.ClientInfoFrom;
/**
* MyEclipse Struts
* Creation date: 10-27-2007
*
* XDoclet definition:
* @struts.action path="/customer" name="customerForm" input="/form/customer.jsp" parameter="method" scope="request" validate="true"
* @struts.action-forward name="error" path="/customer/cuError.jsp"
* @struts.action-forward name="success" path="/customer/cuSuccess.jsp"
*/
public class CustomerAction extends DispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
public ActionForward saveCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IllegalAccessException, InvocationTargetException {
CustomerForm customerForm = (CustomerForm) form;// TODO Auto-generated method stub
ClientInfo info= new ClientInfo();
ClientBusiness cb =new ClientBusiness ();
ClientBusinessInfo cin= new ClientBusinessInfo ();
ClientInfoFrom from= new ClientInfoFrom();
info.setCName(customerForm.getCName());
info.setCEmail(customerForm.getBemail());
info.setCPhone(customerForm.getCPhone());
info.setCQq(new Long( customerForm.getCQq()));
info.setCBlog(customerForm.getCBlog());
info.setCIdCard(customerForm.getCIdCard());
info.setCBirthday(customerForm.getCBirthday());
info.setClientbusiness(cb);
cb.setBName(customerForm.getBname());
cb.setBAddress(customerForm.getBaddress());
cb.setBPhone(customerForm.getBphone());
cb.setBFax(customerForm.getBfax());
cb.setBQq( new Long( customerForm.getBqq()));
cb.setBEmail(customerForm.getBemail());
cb.setBWww(customerForm.getBwww());
cb.setClientinfo(info);
cin.setDBusinessName(customerForm.getDbusinessName());
cin.setDBussinessDept(customerForm.getDBussinessDept());
cin.setDBussinessPerson(customerForm.getDBussinessPerson());
cin.setDPlace(customerForm.getDPlace());
cin.setDBusinesTime(customerForm.getDBusinesTime());
cin.setDCustomerCategory(customerForm.getDCustomerCategory());
cin.setDCustomerClass(customerForm.getDCustomerClass());
cin.setClientinfo(info);
from.setCClass(customerForm.getCClass());
from.setCCraft(customerForm.getCCraft());
from.setCSource(customerForm.getCSource());
from.setRemark(customerForm.getRemark());
from.setClientinfo(info);
BeanUtils.copyProperties(info, customerForm);
BeanUtils.copyProperties(cin, customerForm);
//BeanUtils.copyProperties(cin, customerForm); 就可以代替所有的对象
Operate oper=new Operate();
oper.save(info);
oper.save(cb);
oper.save(cin);
oper.save(from);
return null;
}
}
================jstl 调用action
js代替action提交成功自动关闭刷新当前界面
<script type="text/javascript">
function save(){
if(form1.CName.value==""){
alert("客户姓名不允许为空");
return false;
}
if(form1.BName.value==""){
alert("公司名称不能为空");
return false;
}
else{
var path = '${pageContext.request.contextPath}/costmer/customer.do?method=saveCustomer';
document.forms[0].action = path;
document.forms[0].submit();
alert("保存成功!")
window.close();
}
}
<%-- window.opener.reloadurlthings();--%>
</script>
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- >
- <html:html>
- <head>
- <title>My JSP 'index.jsp' starting pagetitle>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <script type="text/javascript" src="
- head>
- <script type="text/javascript">
- function saves(){
- if(document.form1.names.value <1){
- alert('数据不允许为空');
- return false;
- }
- else{
- return true;
- }
- }
- script>
- <body>
- <br>
- <--!
- <form action="
- -->
- <form action="${pageContext.request.contextPath}/login.do?method=save" method="post" name="form1" onsubmit="return saves()">
- <input type="text" name="names" onclick="setday(this)">
- <input type="submit" value="提交" name="submit" >
- form>
- body>
- html:html>