【问题标题】:accessing url parameter using jstl使用 jstl 访问 url 参数
【发布时间】:2013-08-12 12:18:36
【问题描述】:

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

【问题讨论】:

    标签: jsp servlets jstl


    【解决方案1】:

    试试这个

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

    【讨论】:

    • 谢谢。我认为我对引号的放置也是问题的一部分。 +1 和接受答案的信用。很好的响应时间。
    猜你喜欢
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 2015-04-04
    • 1970-01-01
    • 2016-06-19
    相关资源
    最近更新 更多