I’m new to JSP and JSTL, so I’m probably doing something really dumb here.
I have javax.servlet.jsp.jstl-api-1.2.1 and javax.servlet.jsp.jstl-1.2.1 in my webapps’s lib directory. I’m running on Tomcat7. If it makes any difference, tomcat is being launched by Eclipse. My project is a “Dynamic Web Project”.
web.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>example</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
index.jsp looks like this
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Example</title>
</head>
<body>
<%
String s = "Foo";
%>
<c:out value="${s}" />
<c:out value="Bar" />
</body>
</html>
I expect this to display a page with Foo Bar on it. Instead, it displays just Bar. This happens with all my EL expressions. All my EL expressions seem to be coming up empty.
I’ve seen your self-answer but that’s not the right way:
If you’re already using JSTL with
c:outs anyway avoid using scriptlets altogether and replacewith this:
then printing the value would be:
or simply
${requestScope.s}since thec:outtag isn’t really necessary unless you need to scape XML characters.(
${s}is also fine since the cointainer searches in all the scopes until it finds the first occurrence but, explicitly writting it is cleaner imo)