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

城市联盟网站怎么做seo网站推广价格

城市联盟网站怎么做,seo网站推广价格,云端商城买流量,中国建设教育协会的官方网站spring mvc 文件上传 一、单文件上传 配置步骤#xff1a; 步骤一、在配置文件中配置包扫描器#xff08;暂且这样配#xff0c;会出问题#xff0c;我们下面说解决方案#xff09; ?xml version1.0 encodingUTF-8? beans xmlns…                                                                          spring mvc 文件上传   一、单文件上传 配置步骤 步骤一、在配置文件中配置包扫描器暂且这样配会出问题我们下面说解决方案   ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd !--让spring扫描包下所有的类让标注spring注解的类生效 --context:component-scan base-packagecn.hmy.controller//beans   步骤二定制我们的文件上传jsp页面 % page languagejava importjava.util.* pageEncodingutf-8% % String path request.getContextPath(); String basePath request.getScheme()://request.getServerName():request.getServerPort()path/; %!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN htmlheadbase href%basePath%title文件上传/title/headbodyform action${pageContext.request.contextPath }/list.do methodpost enctypemultipart/form-datah1文件上传/h1文件:input typefile namefileUpLoad//brinput typesubmit value上传/ /form/body /html 步骤三、书写我们的处理器代码 package cn.hmy.controller;import java.io.File; import java.io.IOException;import javax.servlet.http.HttpSession;import org.springframework.stereotype.Controller;import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; import org.springframework.validation.annotation.Validated;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView;import cn.hmy.pojo.UserInfo;Controller public class MyController{//处理器方法RequestMapping(value/list.do) public void doFirst(MultipartFile fileUpLoad,HttpSession session) throws Exception{//1.获取文件名称String filename fileUpLoad.getOriginalFilename();//2.获取文件的前半部分路径String realPath session.getServletContext().getRealPath(/images);//3.拼接成完整的路径File filenew File(realPath,filename);//4.保存文件fileUpLoad.transferTo(file); } } 此时我们启动服务器进行代码上传会报如下错误   解决方案更改我们的spring-servlet.xml配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd !--让spring扫描包下所有的类让标注spring注解的类生效 --context:component-scan base-packagecn.hmy.controller/!--配置复杂类型表达解析器-- bean idmultipartResolver classorg.springframework.web.multipart.commons.CommonsMultipartResolver/bean/beans 启动发现还是会报上述错误  解决方案配置注解驱动 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd !--让spring扫描包下所有的类让标注spring注解的类生效 --context:component-scan base-packagecn.hmy.controller/ !--配置复杂类型表达解析器--bean idmultipartResolver classorg.springframework.web.multipart.commons.CommonsMultipartResolver/bean!--配置注解驱动-- mvc:annotation-driven/ /beans 如果在上述配置文件中缺少复杂类型解析器会报如下错误     在解决了以上错误后我们会发现如果我们上传的文件中含有中文   会出现乱码现象 解决乱码 解决方案我们暂且提供以下两种方式 方案一、 方案二、在web.xml中配置 filterfilter-namecharacterEncoding/filter-namefilter-classorg.springframework.web.filter.CharacterEncodingFilter/filter-classinit-paramparam-nameencoding/param-nameparam-valueutf-8/param-value/init-paraminit-paramparam-nameforceEncoding/param-nameparam-valuetrue/param-value/init-param/filterfilter-mappingfilter-namecharacterEncoding/filter-nameurl-pattern/*/url-pattern/filter-mapping   如何控制文件上传大小 在spring-servlet.xml中配置如下 maxUploadSize为上传的总文件的大小 5MmaxInMemorySize为上传的单个文件的大小 1M bean idmultipartResolver classorg.springframework.web.multipart.commons.CommonsMultipartResolverproperty namedefaultEncoding valueutf-8/propertyproperty namemaxUploadSize value5000000/propertyproperty namemaxInMemorySize value1000000/property/bean 如果超出所限制的大小  会报如下错误     控制文件上传的类型通过后缀名进行控制在处理器中进行判定 例如 只允许上传.jpg   .png   .gif为后缀的文件 package cn.hmy.controller;import java.io.File; import java.io.IOException;import javax.servlet.http.HttpSession;import org.springframework.stereotype.Controller;import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; import org.springframework.validation.annotation.Validated;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView;import cn.hmy.pojo.UserInfo;Controller public class MyController{//处理器方法RequestMapping(value/list.do) public String doFirst(MultipartFile fileUpLoad,HttpSession session) throws Exception{//1.获取文件名称String filename fileUpLoad.getOriginalFilename();//限定文件上传的类型if(filename.endsWith(jpg)||filename.endsWith(png)||filename.endsWith(gif)){//2.获取文件的前半部分路径String realPath session.getServletContext().getRealPath(/images);//3.拼接成完整的路径File filenew File(realPath,filename);//4.保存文件fileUpLoad.transferTo(file); }else{System.out.println(不支持上传文件的类型);}return /list.jsp;} }       如何判断用户没用选上传文件     多文件上传 步骤一、 spring-servlet.xml配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:phttp://www.springframework.org/schema/pxmlns:mvchttp://www.springframework.org/schema/mvcxmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd !--让spring扫描包下所有的类让标注spring注解的类生效 --context:component-scan base-packagecn.hmy.controller/bean idmultipartResolver classorg.springframework.web.multipart.commons.CommonsMultipartResolverproperty namedefaultEncoding valueutf-8/propertyproperty namemaxUploadSize value5000000/propertyproperty namemaxInMemorySize value1000000/property/beanmvc:annotation-driven/ /beans   步骤二、准备多文件上传的jsp页面 % page languagejava importjava.util.* pageEncodingutf-8% % String path request.getContextPath(); String basePath request.getScheme()://request.getServerName():request.getServerPort()path/; %!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN htmlheadbase href%basePath%title文件上传/title/headbodyform action${pageContext.request.contextPath }/list.do methodpost enctypemultipart/form-datah1文件上传/h1文件1:input typefile namefileUpLoad//br文件2:input typefile namefileUpLoad//br文件3:input typefile namefileUpLoad//brinput typesubmit value上传/ /form/body /html 步骤三、编写处理器的代码 //多文件上传RequestMapping(value/list.do) public String doFirst2(RequestParam MultipartFile[] fileUpLoad,HttpSession session) throws Exception{for (MultipartFile item : fileUpLoad) {//1.获取文件名称String filename item.getOriginalFilename();//限定文件上传的类型if(filename.endsWith(jpg)||filename.endsWith(png)||filename.endsWith(gif)){//2.获取文件的前半部分路径String realPath session.getServletContext().getRealPath(/images);//3.拼接成完整的路径File filenew File(realPath,filename);//4.保存文件item.transferTo(file); }else{System.out.println(不支持上传文件的类型);}}return /list.jsp;} 注意在处理器方法中一定要对参数进行校对使用注解RequestParam校正参数 丢到  会报错 即可实现多文件上传  转载于:https://www.cnblogs.com/hmy-1365/p/6104501.html
http://www.pierceye.com/news/740635/

相关文章:

  • 路由器做服务器做网站怎么在百度发布免费广告
  • 惠州网站制作推广做响应式网站设计做图怎么搞
  • 天津高端网站设计公司美食网页设计图
  • 做柱状图饼状图好看的网站四川省住房和城乡建设厅证书
  • 网站建设公司模版wordpress自适应站点
  • 怎么在百度上创建网站wordpress时间轴页面
  • 网站建设公司济宁深圳互联网营销外包
  • 交互设计产品榆林网站seo
  • 唯品会网站开发招聘英文网站公司
  • 网站的推广一般有什么方式韩城网站建设韩城网站推广
  • 书城网站开发四川省建设厅网站投诉
  • 想要个网站沈阳网站备案
  • 网站建设分哪些类别谁有做爰网站号
  • 建设电子票务系统的网站需要多少钱网站开发一对一
  • 网站规划可以分成哪几步上海营销型网站制作
  • gta5 网站正在建设中新品发布会ppt
  • 做的网站每年需要续费idc网站源码
  • 备案主体负责人和网站负责人新网站 seo
  • 网站后台有什么用wordpress 不显示账号名
  • 另类小说 Wordpress长沙seo步骤
  • 网站建设7个基37网游官网
  • 网站设计存在的问题建筑设计私活平台
  • 网站如何做淘宝支付宝wordpress多站点不显示
  • 关于设计的网站免费注册公司
  • 网站建设排名北京网站排名降级的原因有哪些
  • 介绍网页设计做seo推广网站
  • 建立个人博客网站wordpress东城东莞网站建设
  • 从哪些方面建设网站泰州东方医院
  • 分类信息网站系统cmsWordPress新闻面包屑主题
  • wordpress 多标签关键字优化策略