Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未显示JSTL变量_Java_Spring_Spring Mvc_Jstl_Netbeans 7 - Fatal编程技术网

Java 未显示JSTL变量

Java 未显示JSTL变量,java,spring,spring-mvc,jstl,netbeans-7,Java,Spring,Spring Mvc,Jstl,Netbeans 7,我一直在做一些Spring教程,但都在视图使用JSTL打印变量的阶段失败 观点: <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ include file="/WEB-INF/jsp/include.jsp" %> <!DOCTYPE html> <html> <head><title><fmt:message key="title"/>&l

我一直在做一些Spring教程,但都在视图使用JSTL打印变量的阶段失败

观点:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<!DOCTYPE html>
<html>
 <head><title><fmt:message key="title"/></title></head>
  <body>
   <h1><fmt:message key="heading"/></h1>
   <p><fmt:message key="greeting"/><c:out value="${model.now}"/></p>
   <h3>Products</h3>
   <c:forEach items="${model.products}" var="prod">
    <c:out value="${prod.name}"/> <i>$<c:out value="${prod.number}"/></i><br><br>
   </c:forEach>
  </body>
 </html>
JSTL在我的libraries文件夹中(我正在使用NetBeans)

有人知道为什么这种情况一直发生,却什么都没有呈现吗

这是控制器:

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse            response)
throws ServletException, IOException 
    { 
    String now = (new java.util.Date()).toString();
    logger.info("Returning hello view with " + now);

    Map<String, Object> myModel = new HashMap<String, Object>();
    myModel.put("now", now);
    myModel.put("product", this.productManager.getProducts());
    return new ModelAndView("hello", "model", myModel);
}
公共模型和视图HandlerRequest(HttpServletRequest请求,HttpServletResponse响应) 抛出ServletException、IOException { String now=(new java.util.Date()).toString(); logger.info(“使用“+now”返回hello视图); Map myModel=newhashmap(); myModel.put(“现在”,现在); myModel.put(“product”,this.productManager.getProducts()); 返回新模型和视图(“你好”,“模型”,myModel); } web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
si:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener- class>
</listener>

<servlet>
    <servlet-name>springapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

上下文配置位置
/WEB-INF/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
springapp
org.springframework.web.servlet.DispatcherServlet
1.
springapp
*.htm
30
index.jsp

只需将表单标签指定为:

    <html>
    <head>
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    </head>
    <body">
    <form:form id="model" modelAttribute="model">
        <h1><fmt:message key="heading"/></h1>
        <p><fmt:message key="greeting"/><c:out value="${model.now}"/></p>
    </form:form>
    </body> 
    </html> 


添加以下标记库:

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

还有


最后,确保您的类路径上有JSTL 1.2 taglib依赖项,并且成功地发现了这不起作用的原因:


我在servlet中错误地映射到我的hello视图,它正在加载页面,但没有正确加载模型,因此为什么没有显示变量

howz指定的表单标记?您需要向我们显示您正在使用的spring控制器已添加,感谢您如何在jsp中指定form:form标记或其他任何内容。Prasad:没有form:form标记吗?目前,我所做的只是在servlet中声明一些产品,然后尝试在页面上显示它们,恐怕没有任何区别:(类路径中是否有jstl 1.2 jar?另外,一旦指定form:form,通过${model.now}访问“now”是的,没有区别…:(brainZap指定c标记在include.jspAdding
中不起作用,但是目前我看到的是JSTL 1.1加载页面而不是模型是什么意思?
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>