经常写web工程,就会涉及很多路径问题,今天复习下绝对路径和相对路径,以提醒自己下次不要以为路径问题头疼。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>提交一个数</title>
</head>
<body>
<form action="path" method="post">
请输入一个数字: <input type="text" name="number"/>
<input type="submit" value="测试获得路径" />
</form>
</body>
</html>action写的是path,那么,提交后,就会把http://localhost:8080/day/tijiao.html链接中的tijiao.html替换为path变为http://localhost:8080/day/path,这就是所谓的相对于当前的url。<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>提交一个数</title>
</head>
<body>
<form action="<%=request.getContextPath()%>/path" method="post">
请输入一个数字: <input type="text" name="number"/>
<input type="submit" value="测试获得路径" />
</form>
</body>
</html><%=request.getContextPath()%>就可以获取部署的跟路径了。原文:http://blog.csdn.net/u012814506/article/details/45440125