Reputation: 1817
I have been trying out Spring framework and while trying to print java-class attributes in jsp file I have hit a little snag. While trying to print the date to my page I get nothing. I know there is a value in the variable as I can see it in the console but on the page there is nothing. Here is my index.jsp where the value should be shown:
<!-- contains taglibraries -->
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello :: Spring Application</title>
</head>
<body>
<h1>Hello - Spring Application</h1>
<h2>Testing tags</h2>
<p> <c:out value="If you see this then C-tag works."/> </p>
<h2>Testing values brought from controller. One should see a date after "now".</h2>
<p>Greetings, it is now <c:out value="${now}"/></p>
</body>
</html>
And here is my indexController.java:
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class IndexController implements Controller{
protected Log logger = LogFactory.getLog(getClass());
@Override
public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
String now = (new Date()).toString();
logger.info("Returning hello view and " + now);
return new ModelAndView("WEB-INF/jsp/index.jsp" , "now" , now);
}
}
Could someone point out what is it I am doing wrong? Oh and just to clarify: the "include.jsp" contains all my taglibraries so missing taglibrary like this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Is not a problem as the first c-tag on the index.jsp works. The problem is the second c-tag with the variable "now" which refuses to show.
Upvotes: 1
Views: 6402
Reputation: 47280
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
not including that in your jsp
Upvotes: 2