一个表单不同的提交方式和路径

1.表单

<form method="POST" enctype="multipart/form-data" action="/upload" id="upLoad">
    <div class="form-group">
        <p>gid: <input type="text" name="gid" id="gid"/>p>
    div>
    <div class="form-group">
        <input type="file" name="file" id="file"/>
    div>
    
    <input type="button" id="upLoadButton" th:οnclick="'javascript:upLoad()'" th:value="上传"/>
    <input type="button" id="checkButton" th:οnclick="'javascript:checkUploadButton()'" th:value="查看已上传图片"/>
form>
2.js提交代码

function upLoad() {
    var gid = document.getElementById("gid");
    var file = document.getElementById("file");
    if (gid.value == null || gid.value == "") {
        alert("你没有输入gid");
    } else if (file.value == null || file.value == "") {
        alert("你没有选中文件");
    } else {
        document.getElementById("upLoad").action = "/upload";
        document.getElementById("upLoad").method = "post";
        document.getElementById("upLoad").submit();
    }
}

function checkUploadButton() {
    var gid = document.getElementById("gid");
    if (gid.value == null || gid.value == "") {
        alert("你没有输入gid");
    } else {
        document.getElementById("upLoad").action = "/checkUpload";
        document.getElementById("upLoad").method = "post";
        document.getElementById("upLoad").submit();
    }
}


你可能感兴趣的:(java基础,Spring-Boot)