1

我一直在尝试 Spring 框架,并在尝试在 jsp 文件中打印 java-class 属性时遇到了一些问题。在尝试将日期打印到我的页面时,我什么也没得到。我知道变量中有一个值,因为我可以在控制台中看到它,但在页面上什么都没有。这是我的 index.jsp,其中应该显示值:

    <!-- 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>

这是我的 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);        

    }  
}

有人可以指出我做错了什么吗?哦,只是澄清一下:“include.jsp”包含我所有的标签库,所以缺少这样的标签库:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

不是问题,因为 index.jsp 上的第一个 c-tag 有效。问题是带有变量“now”的第二个 c-tag 拒绝显示。

4

1 回答 1

2
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

不包括在你的jsp中

于 2012-07-13T10:02:59.447 回答