J'ai essayé Spring framework et en essayant d'imprimer des attributs java-class dans le fichier jsp, j'ai rencontré un petit problème. En essayant d'imprimer la date sur ma page, je n'ai rien. Je sais qu'il y a une valeur dans la variable comme je peux le voir dans la console mais sur la page il n'y a rien. Voici mon index.jsp où la valeur doit être indiquée:Spring: impression de variables en jsp page
<!-- 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>
Et voici mon 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);
}
}
Quelqu'un pourrait-il indiquer ce qu'il est que je fais mal? Oh, et juste pour clarifier: le « include.jsp » contient tous mes taglibraries donc portés disparus taglibrary comme ceci:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
est-ce pas un problème la première c-étiquette sur les travaux de index.jsp. Le problème est le deuxième c-tag avec la variable "now" qui refuse de montrer.