<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize"> <value>104857600</value> </property> <property name="maxInMemorySize"> <value>4096</value> </property> </bean>
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="../commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>发布资讯</title>
<script type="text/javascript" src="${ctx}/resources/new_js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/ajaxfileupload.js"></script>
<script type="text/javascript">
function save(){
var typeId = $("#type_span_info").attr("data-id");
if (typeof (typeId) == "undefined") {
$("#type_p_info").show();
return;
} else {
$("#type_p_info").hide();
}
var title = $("#title_input_info").val();
var summary = $("#summary_input_info").val();
var content = $("#content_textarea_info").val();
$.ajaxFileUpload({
url : "${ctx}/info/doUpload",
secureuri : false,//是否需要安全协议
fileElementId : 'file',
type : 'POST', //文件提交的方式
dataType : 'string',
cache : false, //是否进行页面缓存
async : true, // 是否同步提交
success : function(data) {
$.ajax({
url : '${ctx}/info/addInfo?fileUrl='+data,
type : 'post',
data:{title:title,summary:summary,content:content,typeId:typeId},
async : false,
success : function(result) {
if (result == 1) {
$("#del_prompt_p").text("添加成功");
fnError3();
} else if (result == 2) {
$("#del_prompt_p").text("添加失败")
fnError2();
} else {
$("#del_prompt_p").text("系统错误");
fnError2();
}
}
});
}
});
}
</script>
</head>
<body class="body_bg">
<div class="main">
<!--页面主体 start-->
<div class="main_content">
<div class="later_index clear wrap">
<div class="later_right fr">
<div class="roll_parent" id="roll_parent">
<div class="scroll_parent" id="scroll_parent">
<div class="scroll" id="scroll"></div>
</div>
<div class="roll_son" id="roll_son">
<div class="later_content later_content1">
<div class="release_name">
<h3>
<span>发布资讯</span>
</h3>
</div>
<div class="issue_content">
<form action="" id="form1" method="post" enctype="multipart/form-data">
<table class="issue_tab">
<tbody>
<tr>
<td><p><i>*</i><strong>标题</strong></p>
</td>
</tr>
<tr>
<td><input id="title_input_info" name="title_input_info" type="text" placeholder="最多可以输入40个字" type="text" maxlength="40"/>
<!-- <span class="colse"></span> -->
<p class="colse_tip"></p>
<!-- <p class="colse_tip" id="title_p_info" style="display:hidden;">请选择标题!</p> -->
</td>
</tr>
<tr>
<td><p><i>*</i><strong>摘要</strong></p></td>
</tr>
<tr>
<td><input name="summary_input_info" id="summary_input_info" type="text" placeholder="最多可以输入100个字" type="text" maxlength="100" />
<p class="colse_tip"></p></td>
</tr>
<tr>
<td><p><i>*</i><strong>内容</strong></p>
</td>
</tr>
<tr>
<td><textarea name="content_textarea_info" id="content_textarea_info"></textarea>
<p class="colse_tip"></p></td>
</tr>
<tr>
<td><p><i>*</i><strong>选择行业</strong></p>
<p class="colse_tip" id="type_p_info" style="display:hidden;">请选择行业!</p></td>
</tr>
<tr>
<td>
<div class="next_select select_width select_bg" id="next_select0">
<span id="type_span_info">请选择</span>
</div>
<div class="select_box select_top select_width" data-id="" id="select_box0">
<ul>
<li class="curr" data-id="2">化工</li>
<li data-id="3">装备制造</li>
<li data-id="4">生物医药</li>
<li data-id="5">电子信息</li>
<li data-id="6">其他</li>
</ul>
</div>
</td>
</tr>
<tr>
<td>
<input type="button" class="isue_inp_btn" value="添加图片"/>
<input type="text" id="issue_input_text" class="issue_text" />
<input type="file" id="file" name="file" class="issue_file" onchange="javaScript:validate_img(this)" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div class="financial_pro_icon">
<div class="financial_pro_icon_l issue_btn1">
<a href="javaScript:save();">发布</a>
</div>
<div class="financial_pro_icon_r issue_btn1">
<a href="${ctx}/info/gotoInfo?index=2">取消</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--页面主体 end-->
</div>
</body>
</html>
//文件上传
@RequestMapping(value = "/doUpload", method = RequestMethod.POST, produces = "text/html; charset=UTF-8")
@ResponseBody
public String doUpload(HttpServletRequest request, HttpServletResponse response) throws IOException {
List<String> fileNames = null;
if (request instanceof MultipartHttpServletRequest) {
// process the uploaded file
logger.info("=====进入文件类型选择=====");
fileNames = uploadAttachment(request, "file");
}
String url = "";
if (fileNames.size() > 0) {
for (int i = 0; i < fileNames.size(); i++) {
url = url + fileNames.get(i);
if(i < fileNames.size() - 1){
url = url + ",";
}
}
}
return url;
}
//文件上传的工具类
public List<String> uploadAttachment(HttpServletRequest request, String type) throws IOException {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<MultipartFile> files = multipartRequest.getFiles(type);
logger.info("数据长度========>>>>>>>>>>" + files.size());
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH) + 1;
String realPath = PropertiesUtil.getProperty("realPath");
System.err.println("realpath=====>>>>>" + realPath);
//String savePath = request.getSession().getServletContext().getRealPath("/") + "p_image\\" + type + "\\" + year+ "\\" + month + "\\";
String savePath = "government"+ File.separator + "image"+ File.separator + year+ File.separator + month + File.separator;
logger.info("保存路径=====>" + savePath);
List<String> fileNames = new ArrayList<String>();
for (MultipartFile multipartFile : files) {
logger.info("--" + multipartFile.getOriginalFilename());
String fileName = multipartFile.getOriginalFilename();
String prefix = fileName.substring(fileName.lastIndexOf(".") + 1);
String custName = "" + System.currentTimeMillis() + "." + prefix;
if (UsedUtil.isNotNull(fileName)) {
File targetFile = new File(realPath+savePath, custName);
// fileName = year+"-"+month+"-"+fileName;
if (!targetFile.exists()) {
targetFile.mkdirs();
multipartFile.transferTo(targetFile);
}
try {
} catch (Exception e) {
e.printStackTrace();
}
fileNames.add(savePath + custName);
}
}
return fileNames;
}
//添加咨询
@RequestMapping(value = "/addInfo", method = RequestMethod.POST)
@ResponseBody
public Integer addInfo(HttpServletRequest request, HttpServletResponse response,
@RequestParam String fileUrl) {
InfoBean bean = new InfoBean();
if(UsedUtil.isNotNull(fileUrl)){
bean.setImagePath(fileUrl);
}
Map<String, Object> paramMap = ControllerUtil.request2Map(request);
bean.setTitle((String) paramMap.get("title"));
bean.setSummary((String) paramMap.get("summary"));
bean.setContent((String) paramMap.get("content"));
bean.setTypeId((String)paramMap.get("typeId"));
return infoService.insInfo(bean);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有