zoukankan      html  css  js  c++  java
  • Java源码文件上传

    jsp页面:

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>测试文件上传</title>

        <script type="text/javascript">

        function urlP(path){

          document.getElementById("p").value=path;

        }

       </script>
    </head>
    <body>

    <form action="对应的路径"  method="post">

    <input type="file" name="upload" onchange="urlP(this.value)">

    <input type="hidden" name="p" id="p">

    </form>
    </body>
    </html>

    SpringMVC框架中的对应的Controller方法:

    @RequestMapping("/save")
    public void save(MultipartFile upload,String p,HttpServletRequest request) throws IOException {
            if(upload!=null){
                String realPath = request.getSession().getServletContext().getRealPath("/WEB-INF/upload");//先获取项目的发布到的路径,再拼接出上传的文件所存放的路径
                FileUtils.copyInputStreamToFile(upload.getInputStream(), new File(realPath, upload.getOriginalFilename()));//保存文件到指定位置
                String filePath=realPath+"\"+p;    //只获取文件名以及扩展名
                audition.setAnnuxPath(filePath);
                auditionService.save(audition);
            }

    }

  • 相关阅读:
    定时器
    SysTick
    13.看门狗
    12.FSMC
    11.中断
    ##HTML行内块元素好迷啊!!
    ##HTML基础
    ##CS3动画效果
    ##管家婆项目(tools层)
    ##管家婆项目(app层)
  • 原文地址:https://www.cnblogs.com/jiangye/p/3512369.html
Copyright © 2011-2022 走看看