JSP里的basePath
2017-05-23 15:36
176 查看
参考文章:
jsp中的basePath和path (绝对路径 相对路径)
basePath的作用
当前所在的路径:
下面是所要请求的代码。
用下面的相对路径:
相比上面多加一个斜杠‘/’但是下面的两种效果就不同了。
效果是:
绝对路径:
在head标签中加入
下面就可以用绝对路径了。
jsp中的basePath和path (绝对路径 相对路径)
basePath的作用
当前所在的路径:
http://localhost:8000/forum/forum/userLockManagePage.html
下面是所要请求的代码。
@RequestMapping(value = "/forum/userLockManage", method = RequestMethod.POST) public ModelAndView userLockManage(@RequestParam("userName") String userName ,@RequestParam("locked") String locked) { ModelAndView view =new ModelAndView(); User user = userService.getUserByUserName(userName); if (user == null) { view.addObject("errorMsg", "用户名(" + userName + ")不存在"); view.setViewName("/fail"); } else { user.setLocked(Integer.parseInt(locked)); userService.update(user); view.setViewName("/success"); } return view; }
用下面的相对路径:
<body> <%@ include file="includeTop.jsp" %> //当前路径:http://localhost:8000/forum/forum/userLockManagePage.html //下面的两种是等效果的,都是相对于当前路径去请求:http://localhost:8000/forum/forum/userLockManage.html <!-- <form action="userLockManage.html" method="post" > --> <form action="<c:url value="userLockManage.html" />" method="post" > <table border="1px" width="100%"> <tr> <td width="20%">用户</td> <td width="80%"><select name="userName"> <option>请选择</option> <c:forEach var="user" items="${users}"> <option value="${user.userName}">${user.userName}</option> </c:forEach> </select></td> </tr> <tr> <td width="20%">锁定/解锁</td> <td width="80%"> <input type="radio" name="locked" value="1" />锁定 <input type="radio" name="locked" value="0" />解锁 </td> </tr> <tr> <td colspan="2"> <input type="submit" value="保存"> <input type="reset" value="重置"> </td> </tr> </table> </form> </body>
相比上面多加一个斜杠‘/’但是下面的两种效果就不同了。
<form action="/userLockManage.html" method="post" > <form action="<c:url value="/userLockManage.html" />" method="post" >
效果是:
<form action="/userLockManage.html" method="post" > <form action="<c:url value="/forum/userLockManage.html" />" method="post" >
绝对路径:
<% String path = request.getContextPath(); String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; // http://localhost:8000/forum/ %>
在head标签中加入
<base href="<%=basePath %>" />
下面就可以用绝对路径了。
<form action="<c:url value="/forum/userLockManage.html" />" method="post" > </form> 请求:http://localhost:8000/forum/forum/userLockManage.html
相关文章推荐
- JSP里的basePath
- JSP中basepath和path的介绍
- jsp中的basePath和path
- (6)开发收获 <base href="<%=basePath%>">JSP页面中的相对路径问题
- 【web JSP basePath】basePath的含义
- JSP里的basePath
- JSP页面中path和basepath的含义
- jsp中的basePath
- JSP中的basepath的使用说明
- JSP中<base href="<%=basePath%>">作用
- MyEclipse中建立的jsp文件中<base href="<%=basePath%>">可能会带来的问题.
- JSP中<base href="<%=basePath%>">对相对路径的影响
- 在jsp页面中使用basePath
- 在jsp中默认写上的一段java代码表示basePath 的路径的具体的意思是什么?
- JSP中<base href="<%=basePath%>">作用
- jsp 中的 basePath 和 path
- JSP中<base href="<%=basePath%>">作用
- JSP中<base href="<%=basePath%>">作用
- 解决JSP页面中路径问题的方法(jsp文件开头path, basePath作用)
- JSP中<base href="<%=basePath%>">作用