2025-10-11 02:17:59 玩家互动社区

比如你的页面路径是:http://localhost:8080/projectname/resource/index.html

url请求最后加.do是为了服务器区分这个请求是静态资源还是servlet请求(后边有.do就是servlet请求)

1、相对于网站根目录可以用"/"开始 (根目录是指服务器的根目录,不是你项目的根目录)

$.ajax({

url:"/getData.do"

})

请求的路径是:http://localhost:8080/getData.do

2、“…/”表示页面目录的上一级目录

$.ajax({

url:"../getData.do"

})

请求的路径是:http://localhost:8080/projectname/getData.do

3、项目的根路径

$.ajax({

url:"getdata.do"

})

请求的路径是:http://localhost:8080/projectname/getData.do

4、全路径

$.ajax({

url:"http://localhost:8080/projectname/getdata.do"

})

请求的路径是:http://localhost:8080/projectname/getdata.do

springMVC如果是这样写的请求映射

如果我们要请求register这个方法,url:…/user/register.do这样写

因为页面路径是这样http://localhost:8080/projectname/resource/index.html

让servlet映射请求跟在项目路径http://localhost:8080/projectname后面就可以了。

最终请求的路径是http://localhost:8080/projectname/user/register.do

转载;https://blog.csdn.net/wsadzxcleg/article/details/80107967?biz_id=102&utm_term=%E8%AF%B7%E6%B1%82%E5%9C%B0%E5%9D%80%E5%90%8E%E5%8A%A0.do&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-2-80107967&spm=1018.2118.3001.4449