当前位置: 首页 > news >正文

湖北网站建设多少钱/百度做网站推广的费用

湖北网站建设多少钱,百度做网站推广的费用,生活中的科技产品有哪些,哪个网站做图找图片做项目是需要将本地图片上传到服务器,可是tiny_mce自带的image插件不能很好的实现, tiny_mce需要动的输入图片地址,这个地址还得是服务器上的地址。所以不满足需要,需要改进。 通常的办法就是使用ajax把图片提交到服务器&#xff…

做项目是需要将本地图片上传到服务器,可是tiny_mce自带的image插件不能很好的实现, tiny_mce需要动的输入图片地址,这个地址还得是服务器上的地址。所以不满足需要,需要改进。

通常的办法就是使用ajax把图片提交到服务器,然后返回图片在服务器上的地址,然后再把返回的地址写到地址栏里,这就ok了。

下面给出我写的代码:

如果你不懂ajaxfileupload请看http://www.phpletter.com/Our-Projects/AjaxFileUpload/

jsp页面:需要引入jquery.js 和ajaxfileupload.js,注意jquery.js需要放在前面,如果放在后面的话,不会执行下面的方法。

<script type="text/javascript" src="../../../js/jquery.js"></script><script type="text/javascript" src="../../utils/ajaxfileupload.js"></script>

<script  type="text/javascript">function uploadFiles() {$.ajaxFileUpload({	    	url:'http://localhost:8080/fangdo/admin/uploadPhoto.action',        secureuri:false,fileElementId:'file',dataType: 'json',success: function (result, statu) {    if (result.status == 'success'){$("#src").val(result.src);ImageDialog.showPreviewImage(result.src);}else {alert(result.status);}},error: function (result, status, e) {    alert(e);}})}
</script>

<tr><td><a href="#" onClick="uploadFiles();"><script>document.write('\文件上传')</script></a></td>							<td><input style="WIDTH: 250" id="file" name="file" type="file"></td>
</tr>

action中的方法:

// photo uploadpublic void uploadPhoto() throws ActionException {String realDir = getSession().getServletContext().getRealPath("");HttpServletRequest request = ServletActionContext.getRequest();String contextpath = request.getContextPath();String basePath = request.getScheme() + "://" + request.getServerName()+ ":" + request.getServerPort() + contextpath + "/";String status = "error";try {String filePath = "uploads";String imagePath = "image" ;String realPath = realDir + "\\" + filePath+"\\"+imagePath;// 判断路径是否存在,不存在则创建File dir = new File(realPath);if (!dir.isDirectory())dir.mkdir();Check that we have a file upload requestif (ServletFileUpload.isMultipartContent(request)) {//为什么要判断看后面注 				DiskFileItemFactory dff = new DiskFileItemFactory();dff.setRepository(dir);dff.setSizeThreshold(1024000);Create a new file upload handlerServletFileUpload servletFileUpload = new ServletFileUpload(dff);FileItemIterator fileItemIterator = null;// Parse the requestservletFileUpload.setHeaderEncoding("UTF-8"); // 设置编码,因为我的jsp页面的编码是utf-8的fileItemIterator = servletFileUpload.getItemIterator(request);String tilte = "";// 标题String url = "";String fileName = "";String realFileName = "";while (fileItemIterator.hasNext()) {FileItemStream fis = fileItemIterator.next();try {if (!fis.isFormField() && fis.getName().length() > 0) {fileName = fis.getName();Pattern reg = Pattern.compile("[.]jpg|png|jpeg|gif$");Matcher matcher = reg.matcher(fileName);if (!matcher.find()) {status = "文件格式不对";break;}realFileName = new Date().getTime()+ fileName.substring(fileName.lastIndexOf("."),fileName.length());url = realPath + "\\" + realFileName;BufferedInputStream in = new BufferedInputStream(fis.openStream());FileOutputStream fous = new FileOutputStream(new File(url));BufferedOutputStream out = new BufferedOutputStream(fous);Streams.copy(in, out, true);status="success";} /*else {String fname = fis.getFieldName();if (fname.indexOf("pictitle") != -1) {BufferedInputStream in = new BufferedInputStream(fis.openStream());byte c[] = new byte[10];int n = 0;while ((n = in.read()) != -1) {tilte = new String(c, 0, n);break;}}}
*/} catch (IOException e) {e.printStackTrace();}}HttpServletResponse respone = ServletActionContext.getResponse();respone.setContentType("text/html");respone.setCharacterEncoding("UTF-8");respone.setStatus(200);String retxt = "{src:'" +  contextpath +"/"+ filePath + "/"+imagePath+"/"+ realFileName + "',status:'"+status+"'}";respone.getWriter().print(retxt);}} catch (Exception e) {e.printStackTrace();}}

配置文件:

<action name="uploadPhoto" class="com.fangdo.action.CmsTitleAction" method="uploadPhoto"></action>

注:1、检查request是否是一个上传请求

// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);

静态方法isMultipartContent代码:就是判断contentType是否是multipart/

这就是为什么form类型要设成multipart/form-data吧

public static final boolean isMultipartContent(HttpServletRequest request) {if (!"post".equals(request.getMethod().toLowerCase())) {return false;}String contentType = request.getContentType();if (contentType == null) {return false;}if (contentType.toLowerCase().startsWith(MULTIPART)) {return true;}return false;}

public static final String MULTIPART = "multipart/";

转载于:https://my.oschina.net/winHerson/blog/50530

http://www.lbrq.cn/news/1418725.html

相关文章:

  • 靠做效果图赚钱的网站/微博营销成功案例8个
  • 做网站一定要用服务器吗/百度官方电话号码
  • wordpress+模版仿米拓/宁波seo推广公司排名
  • 网络科技公司网站/网络营销课程培训课程
  • 做快手头像的网站/自己如何制作网站
  • 烟台网站排名优化公司/电商代运营公司排名
  • 用ps做网站/网络推广与推广
  • 商城网站建设报价单/如何添加百度指数
  • 编程需要下载什么软件/关键词优化公司哪家好
  • 当当网站建设目标/百度服务中心人工客服
  • 网站上面的水印怎么做/重庆的seo服务公司
  • 用现成的网站模板只套内容就可以有这样的吗/百度搜索引擎排名
  • 烟台免费网站建设/百度明令禁止搜索的词
  • 政务内网网站群建设/搜索引擎营销的方法不包括
  • 宝鸡做网站公司电话/太原互联网推广公司
  • 一起做网店的类似网站/软文营销文案
  • 百度做网站续费费用/搜一搜百度
  • 哪建设网站/seo刷网站
  • 英文版网站建设方案/东莞seo顾问
  • 我要做个网站/广州信息流推广公司
  • 网络网站关键词/谷歌浏览器在线打开
  • 定位器品牌/旺道seo软件技术
  • 开源企业网站程序/营销推广内容
  • 怎么做自己的视频网站/关键词排名优化系统
  • 如何查看网站是什么语言做的/网络销售技巧
  • 网站设计公司排名前十/58同城安居客
  • 网站如何做跳板/seo优化一般包括哪些内容
  • 营销建设网站制作/百度知道app
  • 网站单页别人是怎么做的/网店推广有哪些方法
  • 华为公司网站建设方案/可以发布推广引流的悬赏平台
  • B站 韩顺平 笔记 (Day 21)
  • ICCV 2025 | Reverse Convolution and Its Applications to Image Restoration
  • error #include<cuda_runtime_api.h>解决方案
  • docker-compose-mysql-定时备份数据库到其他服务器脚本
  • 谈谈《More Effective C++》的条款30:代理类
  • 4. 索引数据的增删改查