`
ninebirds
  • 浏览: 78625 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论
阅读更多

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提交成功自动关闭刷新当前界面

 

xml 代码

<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>

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2.   
  3. <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>  
  4. <%   
  5. String path = request.getContextPath();   
  6. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";   
  7. %>  
  8.   
  9. <!---->>  
  10. <html:html>  
  11.   <head>  
  12.   
  13.        
  14.     <title>My JSP 'index.jsp' starting pagetitle>  
  15.     <meta http-equiv="pragma" content="no-cache">  
  16.     <meta http-equiv="cache-control" content="no-cache">  
  17.     <meta http-equiv="expires" content="0">       
  18.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  19.     <meta http-equiv="description" content="This is my page">  
  20.     <!---->  
  21.     <script type="text/javascript" src="
  22.   head>  
  23.      
  24.   <script type="text/javascript">  
  25.   function saves(){   
  26.   if(document.form1.names.value <1){   
  27.     alert('数据不允许为空');   
  28.      return false;   
  29.   }   
  30.   else{   
  31.   return true;   
  32.     }   
  33.    }   
  34.   script>  
  35.      
  36.   <body>  
  37.      <br>  
  38. <--!           
  39. <form action=
  40.   
  41. -->  
  42.      <form action="${pageContext.request.contextPath}/login.do?method=save" method="post" name="form1" onsubmit="return saves()">  
  43.      <input type="text" name="names" onclick="setday(this)">  
  44.      <input type="submit" value="提交" name="submit" >  
  45.   
  46.      form>  
  47.         
  48.         
  49.   body>  
  50. html:html>  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics