gpt4 book ai didi

java - 调用 java WebServlet 时收到 Ajax 错误 404

转载 作者:行者123 更新时间:2023-12-01 16:54:05 25 4
gpt4 key购买 nike

我在调用 java WebServlet 时收到 Ajax 错误 404。 ajax 调用是:

var csID = $(this).find('option:selected').attr("name");
alert("csID: " + csID);
$.ajax({
type: "GET",
url: "CampSiteLocationView",
cache: false,
data : {
csId: csID,
},
}).fail(function() {
$("#updateLocation").val("");
alert("Failed");//This alert is shown
})
.done(function(campSiteAddress) {
dataType: "text",

alert("Completed");

$("#updateLocation").val(campSiteAddress);
});

WebServelet 是:

@WebServlet("/CampSiteLocationView.java")
public class CampSiteLocationView extends HttpServlet implements Serializable {

private static final long serialVersionUID = 1L;

public String encoded_csId = null;

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("CampSiteLocationView: ");

//Get the variables
encoded_csId = request.getParameter("csId");

//Decrypt variables
byte[] valueDecoded9 = Base64.decodeBase64(encoded_csId);//decoding part
String csId = new String(valueDecoded9);

//Get the list of Camp Sites
String campSiteLocation = MySQLConnection.getCampSiteLocation(csId);

if (campSiteLocation == null || campSiteLocation.isEmpty()) {
response.getWriter().write("No Camp Sites.");
}else{
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(campSiteLocation);
}
}
}

最佳答案

  1. doPost() 替换为 doGet() 因为你的 aJax 调用 type: "GET"

    <
  2. /CampSiteLocationView.java 替换为 @WebServlet 处的 /CampSiteLocationView

关于java - 调用 java WebServlet 时收到 Ajax 错误 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61625547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com