accessing url parameter using jstl
30,785
Try this
<a href='create-course-summary?spid=${param["spid"]}'>add</a>
Author by
CodeMed
Updated on July 09, 2022Comments
-
CodeMed almost 2 years
I am new to jstl and I need help getting a url-string parameter on a jsp that also contains EL markup from an iterated list of objects retrieved from a database. Can someone show me how to fix the code below so that the following line of code populates with an actual number where I am asking for
${param.spid}:
<a href="create-course-summary?spid="${param.spid}>add</a>
Here is the background:
I am calling a servlet with the following url pattern:
view-course-summaries?spid=1
This calls the following
doGet
method in a 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); }
And returns the following 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" %>
-
CodeMed almost 11 yearsThanks. I think my placement of the quotes was part of the problem, also. +1 and credit for accepted answer. Nice response time.