案例52-crm练习新增客户中加入文件上传功能(struts2文件上传)
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>当前位置:客户管理 > 添加客户</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文件上传)的更多相关文章
- JAVAEE——SSH项目实战03:新增客户、数据字典、文件上传和修改客户
作者: kent鹏 转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7145599.html 一.新增客户 1.数据字典 用于枚举项目中有限个数的字典项 (1 ...
- 案例44-crm练习新增客户使用struts2
1 src下配置文件 1 struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYP ...
- 【JAVAEE学习笔记】hibernate01:简介、搭建、配置文件详解、API详解和CRM练习:保存客户
今日学习:hibernate是什么 一.hibernate是什么 框架是什么: 1.框架是用来提高开发效率的 2.封装了好了一些功能.我们需要使用这些功能时,调用即可.不需要再手动实现. 3.所以框架 ...
- JAVAEE学习——hibernate01:简介、搭建、配置文件详解、API详解和CRM练习:保存客户
今日学习:hibernate是什么 一.hibernate是什么 框架是什么: 1.框架是用来提高开发效率的 2.封装了好了一些功能.我们需要使用这些功能时,调用即可.不需要再手动实现. 3.所以框架 ...
- 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom
[源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...
- 配置 CSV Data Set Config 来参数化新增客户信息操作
1.首先根据新增客户信息的http请求,来确定需要参数化的变量,选取符合测试需求且经常变化或未来会变化的变量为需要参数化的变量,如本文中的客户端名称(sys_name).描述(description) ...
- CRM - 销售与客户
一.销售与客户 - 表结构 ---公共客户(公共资源) 1.没有报名 2.3天没有跟进 3.15天没有成单 客户分布表 龙泰 男 yuan 2018-5-1 3天未跟进 龙泰 男 三江 2018-5- ...
- 企业管理CRM不只是客户录入系统
企业在举办营销活动或者展会之后,将会收集到大量的客户信息,将这些信息有效地整理.完善.储存也是一个不小的工程.如果您的企业经常面遇到这样的情况,不妨使用Zoho CRM系统来帮您完成.但是,Zoho ...
- 三个案例带你看懂LayoutInflater中inflate方法两个参数和三个参数的区别
关于inflate参数问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...
随机推荐
- 【IMOOC学习笔记】多种多样的App主界面Tab实现方法(三)
FragmentPagerAdapter+ViewPager 与之前直接用ViewPager不同的是,数组里面放的不再是View,而是Fraagment; 使用FragmentPagerAdapter ...
- 《Linux内核设计与实现》读书笔记(六)- 内核数据结构
内核数据结构贯穿于整个内核代码中,这里介绍4个基本的内核数据结构. 利用这4个基本的数据结构,可以在编写内核代码时节约大量时间. 主要内容: 链表 队列 映射 红黑树 1. 链表 链表是linux内核 ...
- 使用LogParser 将iis日志导入到数据库中
--注意修改日志位置和表名--u_ex180228.log 日志所在位置 --IISLog 表名--IISLog_table_0228 表名"C:\Program Files (x86)\L ...
- XCode9: iPhone is busy: Preparing debugger support for iPhone
这个好像是等一阵子就可以了 参考链接
- 给label添加点击事件
后台代码: lb1.Attributes.Add("onclick", "getSN('" + lb1.Text.Trim() + "')" ...
- 前端JS AES加密 后端PHP AES加解密
<!DOCTYPEhtml> <html> <head> <title>aes demo</title> </head> < ...
- 关于vue项目多页面的配置
基于vue2.0生成项目,一段时间都在找如何配置成多个页面的.网上有这样的例子相对也是比较详细的,但是还是有些许不一样的地方的.所以,我还是记录下来,当然我也是参考了网上的资料的. 当然先来个vue的 ...
- 模板 可并堆【洛谷P3377】 【模板】左偏树(可并堆)
P3377 [模板]左偏树(可并堆) 如题,一开始有N个小根堆,每个堆包含且仅包含一个数.接下来需要支持两种操作: 操作1: 1 x y 将第x个数和第y个数所在的小根堆合并(若第x或第y个数已经被删 ...
- Experimental Educational Round: VolBIT Formulas Blitz A
Description The HR manager was disappointed again. The last applicant failed the interview the same ...
- hive表多种存储格式的文件大小差异,无重复数据
-- 重点,目标表无重复数据 -- dbName.num_result 无重复记录 -- 插入数据 CREATE TABLE dbName.test_textfile( `key` string, ` ...