1 jsp/customer/add.jsp

完整代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<TITLE>添加客户</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="${pageContext.request.contextPath }/css/Style.css" type=text/css rel=stylesheet>
<LINK href="${pageContext.request.contextPath }/css/Manage.css" type=text/css
rel=stylesheet>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/my.js"></script>
<script type="text/javascript">
$(function(){
loadSelect("006","level","cust_level.dict_id"); //cust_level.dict_id是对象驱动的提交方式
loadSelect("002","source","cust_source.dict_id");
loadSelect("001","industry","cust_industry.dict_id");
});
</script> <META content="MSHTML 6.00.2900.3492" name=GENERATOR>
</HEAD>
<BODY>
<!-- 文件上传页面的三个要求
1.表单必须是post提交
2.表单提交类型必须为enctype,多段式提交。
3.文件上传使用<input type="file"/> -->
<FORM id=form1 name=form1
action="${pageContext.request.contextPath }/CustomerAction_add"
method=post enctype="multipart/form-data"> <TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_019.jpg"
border=0></TD>
<TD width="100%" background="${pageContext.request.contextPath }/images/new_020.jpg"
height=20></TD>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_021.jpg"
border=0></TD>
</TR>
</TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15 background=${pageContext.request.contextPath }/images/new_022.jpg><IMG
src="${pageContext.request.contextPath }/images/new_022.jpg" border=0></TD>
<TD vAlign=top width="100%" bgColor=#ffffff>
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
<TR>
<TD class=manageHead>当前位置:客户管理 &gt; 添加客户</TD>
</TR>
<TR>
<TD height=2></TD>
</TR>
</TABLE> <TABLE cellSpacing=0 cellPadding=5 border=0> <TR>
<td>客户名称:</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_name">
</td>
<td>客户级别 :</td>
<td id="level"> </td>
</TR> <TR> <td>信息来源 :</td>
<td id="source"> </td>
<td>客户行业:</td>
<td id="industry"> </td>
</TR> <TR>
<td>固定电话 :</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_phone">
</td>
<td>移动电话 :</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_mobile">
</td>
</TR>
<!-- 文件上传页面的三个要求
1.表单必须是post提交
2.表单提交类型必须为enctype,多段式提交。
3.文件上传使用<input type="file"/> -->
<TR>
<td>图片上传 :</td>
<td>
<input type="file" name="photo">
</td> </TR> <tr>
<td rowspan=2>
<INPUT class=button id=sButton2 type=submit
value=" 保存 " name=sButton2>
</td>
</tr>
</TABLE> </TD>
<TD width=15 background="${pageContext.request.contextPath }/images/new_023.jpg">
<IMG src="${pageContext.request.contextPath }/images/new_023.jpg" border=0></TD>
</TR>
</TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_024.jpg"
border=0></TD>
<TD align=middle width="100%"
background="${pageContext.request.contextPath }/images/new_025.jpg" height=15></TD>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_026.jpg"
border=0></TD>
</TR>
</TBODY>
</TABLE>
</FORM>
</BODY>
</HTML>

2 CustomerAction

完整代码:

package www.test.web.action;

import java.io.File;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven; import www.test.domain.Customer;
import www.test.service.CustomerService;
import www.test.utils.PageBean; public class CustomerAction extends ActionSupport implements ModelDriven<Customer>{ private Customer customer = new Customer(); private CustomerService cs;
private Integer currentPage;
private Integer pageSize; //上传的文件会自动封装到File对象中
//在后台提供一个与前台<input type=file name=photo/> 组件name相同的属性即可。
private File photo;
//在提交的键名后加上固定的后缀FileName,文件的名称会自动封装到属性中。
private String photoFileName;
//在提交的键名后加上固定的后缀ContentType,文件的MIME类型值会自动封装到属性中。
private String photoContentType; //获取客户列表
public String list() throws Exception {
//封装离线查询对象
DetachedCriteria dc = DetachedCriteria.forClass(Customer.class); //判断并封装参数
if(StringUtils.isNotBlank(customer.getCust_name())){
dc.add(Restrictions.like("cust_name", "%"+customer.getCust_name()+"%"));
} //1 调用Service查询分页数据(PageBean)
PageBean pb = cs.getPageBean(dc,currentPage,pageSize);
//2 将PageBean放入request域,转发到列表页面显示
ActionContext.getContext().put("pageBean", pb);
return "list";
} //保存客户
public String add() throws Exception { System.out.println("文件名称:"+photoFileName);
System.out.println("文件MIME类型:"+photoContentType); //将上传文件保存到指定位置
//renameTo相当于剪切==>复制
photo.renameTo(new File("C:/Users/jepson/Pictures/Saved Pictures/"+photoFileName)); //=============================================== //调用service,保存Customer对象
cs.save(customer);
//重定向到Action
return "toList"; } @Override
public Customer getModel() { return customer;
} public CustomerService getCs() {
return cs;
} public void setCs(CustomerService cs) {
this.cs = cs;
} public Integer getCurrentPage() {
return currentPage;
} public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
} public Integer getPageSize() {
return pageSize;
} public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
} public File getPhoto() {
return photo;
} public void setPhoto(File photo) {
this.photo = photo;
} public String getPhotoFileName() {
return photoFileName;
} public void setPhotoFileName(String photoFileName) {
this.photoFileName = photoFileName;
} public String getPhotoContentType() {
return photoContentType;
} public void setPhotoContentType(String photoContentType) {
this.photoContentType = photoContentType;
}
}

案例52-crm练习新增客户中加入文件上传功能(struts2文件上传)的更多相关文章

  1. JAVAEE——SSH项目实战03:新增客户、数据字典、文件上传和修改客户

    作者: kent鹏 转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7145599.html 一.新增客户 1.数据字典  用于枚举项目中有限个数的字典项 (1 ...

  2. 案例44-crm练习新增客户使用struts2

    1 src下配置文件 1 struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYP ...

  3. 【JAVAEE学习笔记】hibernate01:简介、搭建、配置文件详解、API详解和CRM练习:保存客户

    今日学习:hibernate是什么 一.hibernate是什么 框架是什么: 1.框架是用来提高开发效率的 2.封装了好了一些功能.我们需要使用这些功能时,调用即可.不需要再手动实现. 3.所以框架 ...

  4. JAVAEE学习——hibernate01:简介、搭建、配置文件详解、API详解和CRM练习:保存客户

    今日学习:hibernate是什么 一.hibernate是什么 框架是什么: 1.框架是用来提高开发效率的 2.封装了好了一些功能.我们需要使用这些功能时,调用即可.不需要再手动实现. 3.所以框架 ...

  5. 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom

    [源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...

  6. 配置 CSV Data Set Config 来参数化新增客户信息操作

    1.首先根据新增客户信息的http请求,来确定需要参数化的变量,选取符合测试需求且经常变化或未来会变化的变量为需要参数化的变量,如本文中的客户端名称(sys_name).描述(description) ...

  7. CRM - 销售与客户

    一.销售与客户 - 表结构 ---公共客户(公共资源) 1.没有报名 2.3天没有跟进 3.15天没有成单 客户分布表 龙泰 男 yuan 2018-5-1 3天未跟进 龙泰 男 三江 2018-5- ...

  8. 企业管理CRM不只是客户录入系统

    企业在举办营销活动或者展会之后,将会收集到大量的客户信息,将这些信息有效地整理.完善.储存也是一个不小的工程.如果您的企业经常面遇到这样的情况,不妨使用Zoho CRM系统来帮您完成.但是,Zoho ...

  9. 三个案例带你看懂LayoutInflater中inflate方法两个参数和三个参数的区别

    关于inflate参数问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...

随机推荐

  1. jQuery的Validate插件

    http://www.runoob.com/jquery/jquery-plugin-validate.html 项目中的:: $(function () { $('#createDepartment ...

  2. requests模块demo

    import urllib.request import requests from requests.auth import HTTPBasicAuth from requests.auth imp ...

  3. poj3167(kmp)

    题目链接: http://poj.org/problem?id=3167 题意: 给出两串数字 s1, s2, 求主串 s1 中的 s2 匹配数并输出每个匹配的开头位置. 区间 [l, r] 是 s2 ...

  4. linux进程池模型

    static int nchildren;static pid_t* pids;int main(int argc,char**argv){ int listenfd,i; socklen_t add ...

  5. [转载]C#实现获取浏览器信息

      原文地址:C#实现获取浏览器信息作者:flywithme Request.Browser.MajorVersion.ToString();//获取客户端浏览器的(主)版本号 Request.Bro ...

  6. object都有string

    object都有tostringString item=spinner.getSelectedItem().toString();String item01=String.valueOf(spinne ...

  7. Jenkins利用官网上的rpm源安装

    官网网址:https://pkg.jenkins.io/redhat/                (官网上有安装的命令,参考网址) 安装jdk yum install -y java-1.8.0- ...

  8. django 访问静态资源

    urlpatterns = patterns('', url(r'^$', views.show, name='index'), url(r'^static/(?P<path>.*)', ...

  9. [ZJOI2018]历史(LCT)

    这篇还发了洛谷题解 [Luogu4338] [BZOJ5212] 题解 题意 给出一棵树,给定每一个点的 \(access\) 次数,计算轻重链切换次数的最大值,带修改. 先考虑不带修改怎么做 假设 ...

  10. tfs强行签入和删除工作区

    作者:为爱痴狂 原文:http://www.cnblogs.com/splyn/archive/2011/10/31/2230213.html 域用户被网络管理员重建,或者其他用户牵出文档,导致的TF ...