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" %>
No. It is not possible to have JSTL in HTML page.
Java Using JSTLThis allows you to mix HTML, JavaScript, and Java in the same file. Therefore, it is reasonable to expect that at some point we will want to localize a string from within the Java code.
Thymeleaf, JSF, AngularJS, JavaScript, and guava are the most popular alternatives and competitors to JSTL.
JSP lets you even define your own tags (you must write the code that actually implement the logic of those tags in Java). JSTL is just a standard tag library provided by Sun (well, now Oracle) to carry out common tasks (such as looping, formatting, etc.).
Try this
<a href='create-course-summary?spid=${param["spid"]}'>add</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With