1. 程式人生 > >Spring MVC的 表單提交相對路徑異常問題

Spring MVC的 表單提交相對路徑異常問題

表單提交後,action的URL寫的是, saler/release,每次跳轉後都變成saler/saler/release,很顯然是相對路徑沒有搞清楚。

應該弄清楚相對路徑,並在JSP程式碼中加入<base href="<%=basePath%>">,這樣當前頁面能夠在basePath後面append相對路徑,從而找到正確的controller 

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">