首页 > 技术文章 > springMvc <form action="">提交跳转路径问题

JsonShare 2016-07-18 15:18 原文

表单提交后,action的URL写的是, login/login.do,每次跳转后都变成login/ login/login.do,很显然是相对路径没有搞清楚。

应该弄清楚相对路径,并在JSP代码中加入<base href="<%=basePath%>">,这样当前页面能够在basePath后面append相对路径,从而找到正确的controller 

在页面jsp页面顶部引入:

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

在<head>中加入:

<base href="<%=basePath%>">

 

推荐阅读