有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Springboot war文件contextpath不适用于tomcat

使用tomcat并将war文件部署到tomcat时,contextPath不起作用。它在eclipse嵌入tomcat中运行良好。将war文件上传到tomcat时,它跳过了上下文路径

这是我在^{中的脚本。我遵循了这个answer但它仍然不起作用。知道问题是什么吗

<script>
    function updateRow(index) {
        const contextPath= "${pageContext.request.contextPath}";
        storageTypeUrl= $('select[name=storageType]').val() == "session"  ? "sessionOperations" : "operations";
        $.ajax({
            async: false,
            type: "PUT",
            url: contextPath+"/"+storageTypeUrl+"/?index="+index+"&iban="+document.getElementById(index+"iban").value
            +"&businessIdentifierCode="+document.getElementById(index+"businessIdentifierCode").value,
            success: function(data){
                console.log("update Row successful");
            },
            error : function(request,error) {
                alert(error);
            }});
    }
    function createRow() {      
        const contextPath= "${pageContext.request.contextPath}";
        storageTypeUrl= $('select[name=storageType]').val() == "session"  ? "sessionOperations" : "operations";
        $.ajax({
            async: false,
            type: "POST",
            url: contextPath+"/"+storageTypeUrl+"/?iban="+document.getElementById("createIban").value
            +"&businessIdentifierCode="+document.getElementById("createBusinessIdentifierCode").value,
            success: function(data){
                console.log("create Row successful");
            },
            error : function(request,error) {
                alert(error);
            }});
    }
    function deleteRow(index,id) {
        const contextPath= "${pageContext.request.contextPath}";
        storageTypeUrl= $('select[name=storageType]').val() == "session"  ? "sessionOperations" : "operations";
        $.ajax({
            async: false,
            type: "DELETE",
            url: contextPath+"/"+storageTypeUrl+"/?index="+index,
            success: function(data){
                console.log("delete Row successful");
            },
            error : function(request,error) {
                alert(error);
            }});
    }
</script>

如果单击“更新”、“创建”或“删除”,则得到404,URL将跳过contextPath并重定向到localhost:8080,而不是localhost:8080/web-1.0-SNAPSHOT/

GET http://localhost:8080/?storageType=session&accountList%5B0%5D.iban=initIban&accountList%5B0%5D.businessIdentifierCode=initBusinessIdentifierCode&accountList%5B1%5D.iban=&accountList%5B1%5D.businessIdentifierCode= 404

enter image description here

但如果我刷新页面,就会创建新行

enter image description here


共 (0) 个答案