1.首先有两个页面,两个页面的页面结构如下:
一个首页:index.jsp,全限定类名是:
/News/WebContent/WEB-INF/views/home/index/index.jsp
url地址为:http://localhost:8080/News/index/index
另一个新闻详细页:detail.jsp,全限定类名是:
/News/WebContent/WEB-INF/views/home/news/detail.jsp
url地址为:http://localhost:8080/News/news/detail
2.从首页跳转到详情页:
使用相对路径访问:相对路径相对路径就是相对于html页面路径的路径,记住,不是相对于请求的JS文件的路径。
详情页ajax的url: '../news/detail'。
解释:
首页html为/News/WebContent/WEB-INF/views/home/index/index.jsp,相对路径先返回上一层,所以html路径为/News/WebContent/WEB-INF/views/home/,再访问news/detail,最终路径为/News/WebContent/WEB-INF/views/home/news/detail.jsp.
使用绝对路径访问:请求路径以根路径开头,表示ajax在什么页面,该请求都是相对于服务器的根路径,最后的请求路径都是:http://localhost:8080 + (url地址)
详情页ajax的url: '/News/news/datail' 。
解释:
因为请求路径以根开头,所以访问地址为:http://localhost:8080 +/News/news/detail 。