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>
- <%@ 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>
分享到:
相关推荐
struts经典新书2007struts经典新书2007
STRUTS经典笔记STRUTS经典笔记STRUTS经典笔记STRUTS经典笔记STRUTS经典笔记
Struts经典入门篇 孙卫琴的
hibernate+spring+struts经典案例案发地方啊啊发达啊爱上对方案发啊啊打发案发案发啊打发放大 啊发达案发
struts经典教程(孙卫琴高清word版本)
Struts经典入门
struts经典分页
这是一个非常经典的培训教程,本章节是如何进行struts的各类配置和使用
struts经典实例,罗列了所有关于struts知识点
包含了两部自学Struts的精美手册,涉及面比较广泛,携带方便,内置 struts最新前沿技术和Struts标签大全 Struts 1.02 中文手册 jakarta struts中文版 Struts in Action 中文修正版 高级教师专门推荐的
用Struts实现JAVA Web应用的MVC模式
包含Struts的多模块,验证框架,国际化! 登陆使用Cookie技术!
看完这个例子,你可以马上理解struts各个文件之间的关系,迅速制作自己的第一个struts
21个经典专题,讲解清楚。代码完整! doc文件,易于复制代码……
学习struts的经典教程从入门到精通 学习struts的经典教程从入门到精通
Struts教程里面有详细的配置说明 Struts的概念和体系结构(三大架构之一)...
这是关于struts的经典入门的项目,采用了struts+myeclipse,从而可以学习struts的典型知识点的使用。