使用jstl访问url参数

时间:2013-08-10 19:55:04

标签: jsp servlets jstl

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

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

以下是背景资料:

我正在使用以下url模式调用servlet:

view-course-summaries?spid=1  

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

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" %>

1 个答案:

答案 0 :(得分:21)

试试这个

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