9

我是 jstl 的新手,我需要帮助在 jsp 上获取 url 字符串参数,该参数还包含从数据库检索的对象的迭代列表中的 EL 标记。有人可以告诉我如何修复下面的代码,以便下面的代码行填充我要求的实际数字${param.spid}:

<a href="create-course-summary?spid="${param.spid}>add</a>

这是背景:

我正在调用具有以下 url 模式的 servlet:

view-course-summaries?spid=1  

doGet这会在 servlet 中 调用以下方法:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
   throws ServletException, IOException {
    String spidString = req.getParameter("spid");
    Long spid = new Long(spidString);
    List<CourseSummary> coursesummaries = new CourseSummaryDAO().findAllCS(spid);
    req.setAttribute("coursesummaries", coursesummaries);
    jsp.forward(req, resp);
}

并返回以下jsp:

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ include file="admintop.inc" %>
<table>
<tr>
  <td>Name of School (Course Provider):</td>
  <td>will go here</td>
</tr>
<tr><td colspan=2>
<a href="create-course-summary?spid="${param.spid}>add</a>
</td>
</tr>
<tr>
   <td colspan=2>
        <table>
            <tr>
                <th>Type</th>
                <th>Number</th>
                <th>id</th>
            </tr>
            <c:forEach varStatus="loopCounter" items="${coursesummaries}" var="coursesummary">
            <tr>
                <td>
                    <c:out value="${coursesummary.coursetype}" />
                </td>
                <td>
                    <c:out value="${coursesummary.numunits}" />
                </td>
                <td>
                    <c:out value="${coursesummary.id}" />
                </td>
            </tr>
            </c:forEach>
        </table>
   </td>
</tr>
</table>   

<%@ include file="adminbottom.inc" %>
4

1 回答 1

23

尝试这个

<a href='create-course-summary?spid=${param["spid"]}'>add</a>
于 2013-08-10T20:02:31.860 回答