• 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);
            }

    }

  • 相关阅读:
    linux 网络编程比较好的文章
    linux 命令
    感冒了
    aa
    111
    仿京东(我的商城)鼠标上去弹出层效果
    仿汽车之家搜索页价格签区间(鼠标拖拽同时tip提示)
    关于DW 打不开后缀名为.ftl的文件 配置方法
    客户端与服务器段的交互 通过json
    jquery 阻止事件冒泡
  • 原文地址:https://www.cnblogs.com/jiangye/p/3512369.html
Copyright © 2020-2023  润新知