如何将参数从查询传递到另一个JSP页面 [英] How to pass param from a query to another jsp page

查看:72
本文介绍了如何将参数从查询传递到另一个JSP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个JSP页面(display.jps和studentDisplay.jsp). display.jsp显示一张表格,其中包含所有参加的所有学生及其成绩.在学生姓名上也有一个链接,可将他们带到studentDisplay.jsp.我正在尝试获取studentDisplay.jsp来显示已单击的所有学生成绩.我仅使用Java已有一周左右的时间,但在此问题上呆了几天.我确定我没有正确传递参数.任何帮助将不胜感激.

I have two JSP pages (display.jps and studentDisplay.jsp). The display.jsp shows a table with all the student and their grades on all of the tests taken. It also has a link on the students name to take them to the studentDisplay.jsp. I am trying to get the studentDisplay.jsp to show all of the grades of the student that has been clicked on. I have only been working with java for a week or so but I have been stomped on this for a couple of days. Im sure I'm not passing the param right. Any help would be greatly appreciated.

display.jsp

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

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>

推荐答案

在display.jsp中的以下行:

In display.jsp at below line:

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

您正在尝试在查询参数中发送变量.据我所知,查询参数应先发送变量名,然后发送值,但您只发送值.据我说,这段代码应该是这样的:

You are trying to send a variable in query parameter. As far as my understanding is, query params should be sent with variable name and then value, but you are sending only value. According to me, this piece of code should be like this:

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

<a href="studentDisplay.jsp?name=${row.studentName}">

然后,在您的studentDisplay.jsp中,您应该使用名称"变量访问当前的StudentName.

And then, in your studentDisplay.jsp you should access current studentName using "name" variable.

这篇关于如何将参数从查询传递到另一个JSP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆