JSP中的getParameter将null设置为href

问题描述 投票:0回答:1

我有以下情况,这是我的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中。您能帮我解决这个问题吗?我将不胜感激。预先感谢!

java jsp servlets
1个回答
0
投票

直到提交页面之前,您将无法在请求对象中获得periodfaculty的值。

© www.soinside.com 2019 - 2024. All rights reserved.