且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

$就调用没有传递给servlet时,将返回错误"未发现"

更新时间:2022-03-08 19:59:10

当您指定相对URL(一个URL不是以计划或 / ),那么它会成为相对于当前请求的URL(在浏览器地址栏中看到URL)。

When you specify a relative URL (an URL not starting with scheme or /), then it will become relative to the current request URL (the URL you see in browser's address bar).

您告诉你的servlet,请访问:

You told that your servlet is available at:

的http://本地主机:8080 / FullcalendarProject / CheckingAjax

想象一下,你的AJAX脚本运行IS通过打开网页:

Imagine that the web page where your ajax script runs is opened via:

的http://本地主机:8080 / FullcalendarProject /页/ some.jsp

和您指定的相对URL URL:CheckingAjax,那么这将是PTED为跨$ P $:

And you specify the relative URL url: "CheckingAjax", then it will be interpreted as:

的http://本地主机:8080 / FullcalendarProject /页/ CheckingAjax

但是,这并不存在。这将因此返回一个HTTP 404找不到网页错误。

But this does not exist. It will thus return a HTTP 404 "Page Not Found" error.

为了得到它的工作,你基本上需要指定使用以下方法之一的网址:

In order to get it to work, you basically need to specify the URL using one of below ways:

  1. URL:HTTP://本地主机:8080 / FullcalendarProject / CheckingAjax

这是不可移植。你需要每次编辑它,你的Web应用程序移动到另一个域。您无法从Web应用程序内部控制这一点。

This is not portable. You'd need to edit it everytime you move the webapp to another domain. You can't control this from inside the webapp.

URL:/ FullcalendarProject / CheckingAjax

这还算不上便携。你需要编辑它每次你改变了上下文路径。您无法从Web应用程序内部控制这一点。

This is also not really portable. You'd need to edit it everytime you change the context path. You can't control this from inside the webapp.

URL:../ CheckingAjax

这其实也是不可移植的,但你完全可以从Web应用程序内部控制这种情况。你需要每次编辑它在你身边JSP移动到另一个文件夹,但如果你走动的JSP你基本上已经处于繁忙状态的编码,所以这可以很容易地在同一时间完成。

This is actually also not portable, although you can fully control this from inside the webapp. You'd need to edit it everytime you move around JSP into another folder, but if you're moving around JSPs you're basically already busy coding, so this could easily be done at the same time.

***的办法是让JSP EL动态打印当前请求上下文路径。假设JS code被封闭在JSP文件:

Best way would be to let JSP EL dynamically print the current request context path. Assuming that the JS code is enclosed in JSP file:

URL:$ {pageContext.request.contextPath} / CheckingAjax

或者当它封闭在自己的JS文件(很好的做法!),然后创建一个全局变量JS:

Or when it's enclosed in its own JS file (good practice!), then create a global JS variable:

<script>var contextPath = "${pageContext.request.contextPath}";</script>
<script src="yourajax.js"></script>

通过

网​​址:的contextPath +/ CheckingAjax