一、說明:
當頁面的form表達的action=""時,表示表單會提交到當前頁面,但是如果當前頁面的URL里已經帶有一個參數了,每次提交表達時這個參數依然存在,不管form表單里有沒有提交該參數。
例如:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
System.out.println("userid="+request.getParameter("userid"));
System.out.println("username="+request.getParameter("username"));
%>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
This is my JSP page. <br>
<form method="post" id="submit" action="">
<input type="text" name="username" id="username" value=""/> username<br>
<input type="submit" value="提交"/>
</form>
</body>
</html>

若訪問URL為:http://localhost:8080/MyWebPro/index.jsp?userid=1
則控制台打印:
userid=1 username=null
輸入username提交表達可以發現后台打印:
userid=1 username=jack
因此,可以發現,如果action提交到當前頁面時,如果當前頁面URL里帶有參數,則每次提交表單時該參數仍然會被提交。
二、總結:
之前沒有遇過這種情況,今天自己動手測試了一下並記錄下來以備查詢。
