2011-06-09 47 views
0

我有一個帶有多個按鈕的頁面,每個按鈕都有一個名稱和值屬性。點擊按鈕後,該頁面將被重定向到另一個頁面,該頁面在所選按鈕名稱和值的表單的action屬性中給出。使用URL來標識所選按鈕

我想檢索下一頁中附加URL的選定按鈕名稱或ID。我怎樣才能做到這一點?

回答

1

如果您給按鈕一個名稱,那麼它只是作爲請求參數提供。

E.g.

<input type="submit" name="add" value="Add" /> 
<input type="submit" name="edit" value="Edit" /> 
<input type="submit" name="delete" value="Delete" /> 

在servlet的

if (request.getParameter("add") != null) { 
    // Add button was pressed. 
} else if (request.getParameter("edit") != null) { 
    // Edit button was pressed. 
} else if (request.getParameter("delete") != null) { 
    // Delete button was pressed. 
} else { 
    // Handle exceptional/alternative case yourself. 
} 

或JSP

<c:choose> 
    <c:when test="${not empty param.add}"> 
     Add button was pressed. 
    </c:when> 
    <c:when test="${not empty param.edit}"> 
     Edit button was pressed. 
    </c:when> 
    <c:when test="${not empty param.delete}"> 
     Delete button was pressed. 
    </c:when> 
    <c:otherwise> 
     Handle exceptional/alternative case yourself. 
    </c:otherwise> 
</c:choose> 
+0

1進行徹底的例子。 – 2011-06-09 21:14:05

相關問題