[英]getParameter in JSP sets null to href
我有以下情況,有我的 index.jsp 頁面:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Lab2</title>
</head>
<body>
<p>
Period: <input type="number" name="period" size="50">
<br>
Faculty: <input type="text" name="faculty" size="50">
<br>
<br>
<a href="${pageContext.request.contextPath}/calculatePaymentForSeveralSemesters?value=<%=request.getParameter("period")%>&faculty=<%=request.getParameter("faculty")%>">Calculate
payment for several semesters</a>
<a href="${pageContext.request.contextPath}/showTwoSmallestFaculties">Show two smallest faculties</a>
</p>
</body>
</html>
因此,我想使用從輸入中獲得的動態值創建鏈接。 但是我的結果鏈接是http://localhost:8080/Lab2_war_exploded/calculatePaymentForSeveralSemesters?value=null&faculty=null
我不明白為什么輸入的值沒有添加到這個 href 中。 你能幫我解決這個問題嗎? 我將不勝感激任何幫助。 提前致謝!
在提交頁面之前,您將無法獲得請求對象中可用的period
和faculty
的值。
出於演示的目的,我添加了一個帶有submit
按鈕的form
。 輸入period
和faculty
一些值,然后點擊submit
按鈕。 現在檢查鏈接,您會發現它填充了所需的值,例如當您在period
輸入10
並在semester
字段中test
后點擊submit
按鈕時,您會發現鏈接的值為http://localhost:8080/TestDynamicProject/calculatePaymentForSeveralSemesters?value=10&faculty=test
。
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
<title>Lab2</title>
</head>
<body>
<p>
<form>
Period: <input type="number" name="period" size="50"> <br>
Faculty: <input type="text" name="faculty" size="50"> <br>
<a href="${pageContext.request.contextPath}/calculatePaymentForSeveralSemesters?value=<%=request.getParameter("period")%>&faculty=<%=request.getParameter("faculty")%>">Calculate payment for several semesters</a>
<a href="${pageContext.request.contextPath}/showTwoSmallestFaculties">Show two smallest faculties</a>
<input type="submit">
</form>
</p>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.