如何将查询中的param传递给另一个jsp页面

时间:2015-08-01 19:22:22

标签: jsp jstl

我有两个JSP页面(display.jps和studentDisplay.jsp)。 display.jsp显示了一张表,其中列出了所有学生及所有考试成绩。它还有一个学生姓名链接,可以将它们带到studentDisplay.jsp。我正在尝试让studentDisplay.jsp显示已被点击的所有学生成绩。我只用java工作了一个星期左右但我已经踩了几天了。我确定我没有通过正确的参数。任何帮助将不胜感激。

display.jsp

     SELECT * from CWGrades2 ORDER BY grade DESC;
    </sql:query>


    <form>
        <table border="1" width="40%">

            <tr>

                <th>Student Name</th>
                <th>Grade</th>

            </tr>
            <c:forEach var="row" items="${result.rows}">


                <tr>

                    <td><a href=“studentDisplay.jsp?${row.studentName}”>
                            <c:out value="${row.studentName}"/></a></td>
                     <td><c:out value="${row.grade}"/></td>

                </tr>
            </c:forEach>
        </table>
    </form>

studentDisplay.jsp

<c:set var="myVar" >
  <jsp:include page="display.jsp">
  <jsp:param name="myVar2" value="${row.studentName}"/>
  </jsp:include>
   </c:set>

  <sql:query dataSource="${dbsource}” scope="request"  var="result">

 SELECT * from CWGrades2 WHERE studentName=? <sql:param value="${myVar2}"/> ORDER BY grade DESC;
    </sql:query>

    <form>
        <table border="1" width="40%">

            <tr>

                <th>Student Name</th>
                <th>Grade</th>
                <th>Test</th>
            </tr>
            <c:forEach var="row" items="${result.rows}">
                <tr>

                    <td><c:out value="${row.studentName}"/></td>
                     <td><c:out value="${row.grade}"/></td>
                   <td><c:out value="${row.testName}"/></td>
                </tr>
            </c:forEach>
        </table>
    </form>


    <a href="index.jsp">Go Home</a>
</center>

1 个答案:

答案 0 :(得分:0)

在下面一行的display.jsp中:

**<a href=“studentDisplay.jsp?${row.studentName}”>**

您正在尝试在查询参数中发送变量。根据我的理解,查询参数应该使用变量名称然后发送值,但您只发送值。据我说,这段代码应该是这样的:

<强> <a href=“studentDisplay.jsp?name=${row.studentName}”>

然后,在您的studentDisplay.jsp中,您应该使用&#34; name&#34;来访问当前的studentName。变量