最近在学springmvc,发现在路径的带/和不带/上有很多的问题,
所以今天讲一下前端文件,路径带/和不带/的问题
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>主题</title>
</head>
<body>
<!--1.直接写页面在前端的绝对路径-->
<a href="http://localhost:8080/01_primary_war_exploded/in.do">跳转页面</a>
<!--2.写带/的相对路径
前台路径在有/的时候参照路径是:http://localhost:8080
因为 绝对路径=参照路径 + 相对路径 所以为/01_primary_war_exploded/in.do
-->
<a href="/01_primary_war_exploded/in.do">跳转页面</a>
<!--3.不带/的相对路径
前台路径在无/的时候参照路径是当前的访问路径:http://localhost:8080/01_primary_war_exploded
所以应填in.do-->
<a href="in.do">跳转页面</a>
</body>
</html>
后台spring.xml配置时 如果路径为/in.do怎么在浏览器中找到页面
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
">
<!--浏览器必须提交如下绝对路径才能访问到MyController这个资源:
这个路径出现在xml文件里,所以是个后台路径,后台路径参照的是:Web应用根路径
Web根路径为:http://localhost:8080/01_primary_war_exploded/-->
<bean id="/in.do" class="com.bjpowernode.handlers.MyController"/>
</beans>
即为如下路径