java - 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
但是如果我刷新页面,则会创建新行。
解决方案
推荐阅读
- kubernetes - 部署 dhcpd 服务器
- python - sublime text 新版本的键盘快捷键
- php - 为什么尽管获得状态码 200 作为回报,PHP cURL PUT 请求仍不起作用?
- xcode - CodeSign 因非零退出代码而失败
- python-3.x - 为什么 tkinter 输入验证需要调用 register()?
- c# - C#/WinForms:创建组件失败
- python - 优化熊猫数据框列的四分位数?
- xamarin - 多选列表视图
- java - 更改画布上单元格的颜色 onTouch down
- git - 尽管能够进行身份验证,但无法连接与远程盒子中的分支交互