首页 > 解决方案 > Springboot战争文件-上下文路径不适用于tomcat

问题描述

contextPath使用tomcat并将war文件部署到tomcat时不起作用。它在 Eclipse embed Tomcat 中运行良好。将war文件上传到tomcat时会跳过上下文路径。

这是我在index.jsp. 我遵循了这个答案,但它仍然不起作用。知道问题是什么吗?

<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

在此处输入图像描述

但是如果我刷新页面,则会创建新行。

在此处输入图像描述

标签: javaspring-boottomcat

解决方案


推荐阅读