Reputation: 2163
My JSP (source below) isn't displaying the value
attribute of the <c:out>
tag. Based on the code below, my ${param.username}
is being evaluated correctly. The JSP page is accessed with a request parameter of ?username=jeff
.
Any thoughts on why? I feel like I'm missing something simple here.
JSP, output, and source after translation/compilation below:
prac.jsp
<html xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<head><title>Practice JSP</title></head>
<body>
<h2>Practice JSP</h2>
Username: <c:out value="${param.username}" default="No username"/><br/>
</body>
</html>
Output
Practice JSP
Username:
Source (right click, view page source from browser)
<html xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<head><title>Practice JSP</title></head>
<body>
<h2>Practice JSP</h2>
Username: <c:out value="jeff" default="No username"/><br/>
</body>
</html>
Upvotes: 3
Views: 9402
Reputation: 541
Try using this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
this will make jstl tags available to your jsp and solve your problem.
Upvotes: 2
Reputation: 1108852
Here,
<html xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core">
you're declaring the taglib as a XML namespace which works only in JSPX, not in "plain vanilla" JSP. Since you didn't explicitly mention "JSPX" anywhere in the question, even not in the file extension, I gather that you're actually using "plain vanilla" JSP. In that case, a XML namespace isn't going to work. You need to declare the taglib by <%@taglib%>
.
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
Note that I removed the xmlns:jsp
without a @taglib
equivalent, as that's already implicitly done by the JSP parser. On contrary to the XML namespace, you don't need to specify the taglib on your own for http://java.sun.com/JSP/Page
.
Or, if you actually intend to use JSPX, then you should be renaming the file to prac.jspx
.
Upvotes: 6