Spring控制器不显示数据

时间:2016-11-01 18:58:37

标签: java spring spring-mvc

使用此控制器

package com.companyname.springapp.web;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController {

     protected final Log logger = LogFactory.getLog(getClass());

        @RequestMapping(value="/hello.htm")
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {

            String now = (new Date()).toString();
            logger.info("Returning hello view with " + now);

            return new ModelAndView("WEB-INF/views/hello.jsp", "now", now);
        }

}

显示视图

<%@ include file="/WEB-INF/views/include.jsp" %>

<html>
  <head><title>Hello :: Spring Application</title></head>
  <body>
    <h1>Hello - Spring Application</h1>
    <p>Greetings, it is now <c:out value="${now}"/></p>
  </body>
</html>

include.jsp

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

当执行时,视图显示'现在是现在',没有显示日期值,我有一个警告'未知标记(c:out)'我在重定向标记上有相同的警告,但它有效。

jstl jar on maven dependencies list

<dependency>
        <groupId>org.apache.taglibs</groupId>
        <artifactId>taglibs-standard-spec</artifactId>
        <version>1.2.5</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

0 个答案:

没有答案