Spring 无法从JSP页面中的ModelMap获取值

Spring 无法从JSP页面中的ModelMap获取值,spring,jsp,spring-mvc,Spring,Jsp,Spring Mvc,我尝试在我的项目中使用ModelMap,但无法访问JSP页面中的ModelMap值 我的dispatcher-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http:

我尝试在我的项目中使用ModelMap,但无法访问JSP页面中的ModelMap值

我的dispatcher-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/aop 
                http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                http://www.springframework.org/schema/tx 
                http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
                http://www.springframework.org/schema/mvc 
                http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <bean
        class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
    <bean
        class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter">
    </bean>
    <context:component-scan base-package="controller"></context:component-scan>
    <mvc:annotation-driven />

    <!-- Most controllers will use the ControllerClassNameHandlerMapping above, 
        but for the index controller we are using ParameterizableViewController, 
        so we must define an explicit mapping for it. -->
    <bean id="urlMapping"
        class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="index.html">indexController</prop>
            </props>
        </property>
    </bean>

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>org.springframework.web.servlet.view.tiles3.TilesView</value>
        </property>
    </bean>

    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>

    <!-- The index controller. -->
    <bean name="indexController"
        class="org.springframework.web.servlet.mvc.ParameterizableViewController"
        p:viewName="index" />

</beans>
在JSP页面中,我尝试使用:
${title}

但我无法在JSP标题中获得字符串“Home”

请帮我解决这个问题! ----编辑我的JSP页面----


${title}
    Quản LýPhòng Máy
    Quản LýMáy Tính

版权及副本;2016 $(文档).ready(函数(){ $('data-toggle=“tooltip”).tooltip(); });
使用平铺时,可以直接从平铺xml文件指定页面名称 为了做到这一点,您需要执行以下操作

在定义中添加另一个名为title的属性

<definition name="index" template="/WEB-INF/jsp/partical/main.jsp">
    <put-attribute name="title" value="Index" />
    <put-attribute name="content" value="/WEB-INF/jsp/partical/index.jsp" />
</definition>
如果我能给你一个意见,我相信你没有充分利用ApacheTiles所能提供的潜力

ApacheTiles是一个框架,允许您不在每个页面中复制代码。 因此,为网站创建一个基本布局非常重要,然后您可以更改每个页面中的主体

给你举个例子

模板:

<definition name="app.base" template="/WEB-INF/views/template.jsp">
        <put-attribute name="title" value="Not Found" />
        <put-attribute name="body" value="/WEB-INF/views/body.jsp" />
        <put-attribute name="footer" value="/WEB-INF/views/footer.jsp" />
        <put-list-attribute name="stylesheets_top">
            <add-attribute value="/resources/site/library/bootstrap/bootstrap.min.css" />
            <add-attribute value="/resources/site/library/font-awesome/font-awesome.min.css" /> 
        </put-list-attribute>   
        <put-list-attribute name="javascripts_bottom">
            <add-attribute value="/resources/js/jquery/jquery-1.12.0.min.js" />
            <add-attribute value="/resources/site/library/bootstrap/bootstrap.min.js" />
        </put-list-attribute>   
</definition>
<definition name="home" extends="app.base">
        <put-attribute name="title" value="Home" />
        <put-attribute name="body" value="/WEB-INF/jsp/home.jsp" />
        <put-list-attribute name="stylesheets_top" inherit="true">
            <add-attribute value="/resources/site/home/home.css" />
        </put-list-attribute>   
        <put-list-attribute name="javascripts_bottom" inherit="true">
            <add-attribute value="/resources/site/home/home.js" />
        </put-list-attribute>   
</definition>

扩展模板的页面:

<definition name="app.base" template="/WEB-INF/views/template.jsp">
        <put-attribute name="title" value="Not Found" />
        <put-attribute name="body" value="/WEB-INF/views/body.jsp" />
        <put-attribute name="footer" value="/WEB-INF/views/footer.jsp" />
        <put-list-attribute name="stylesheets_top">
            <add-attribute value="/resources/site/library/bootstrap/bootstrap.min.css" />
            <add-attribute value="/resources/site/library/font-awesome/font-awesome.min.css" /> 
        </put-list-attribute>   
        <put-list-attribute name="javascripts_bottom">
            <add-attribute value="/resources/js/jquery/jquery-1.12.0.min.js" />
            <add-attribute value="/resources/site/library/bootstrap/bootstrap.min.js" />
        </put-list-attribute>   
</definition>
<definition name="home" extends="app.base">
        <put-attribute name="title" value="Home" />
        <put-attribute name="body" value="/WEB-INF/jsp/home.jsp" />
        <put-list-attribute name="stylesheets_top" inherit="true">
            <add-attribute value="/resources/site/home/home.css" />
        </put-list-attribute>   
        <put-list-attribute name="javascripts_bottom" inherit="true">
            <add-attribute value="/resources/site/home/home.js" />
        </put-list-attribute>   
</definition>

上面的页面将同时包含父页面和子页面的属性

模板可能如下所示

<title><tiles:insertAttribute name="title" /></title>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<tiles:importAttribute name="stylesheets_top" />
<tiles:importAttribute name="javascripts_bottom" />
<!DOCTYPE html>
<html lang="en">

<head>

<title><tiles:insertAttribute name="title" /></title>

</head>
<body>
    <header>
        <!-- stylesheets top -->
        <c:forEach var="css" items="${stylesheets_top}">
            <link rel="stylesheet" type="text/css" href="<c:url value="${css}"/>">
        </c:forEach>
    </header>
    <div class="body">

        <tiles:insertAttribute name="body" />
    </div>
    <footer class="footer">
        <tiles:insertAttribute name="footer" />
    </footer>

</body>

<!-- scripts_bottom -->
<c:forEach var="script" items="${javascripts_bottom}">
    <script src="<c:url value="${script}"/>"></script>
</c:forEach>

</script>
</html>


请发布您的jsp@redflar3请f5页查看我的更新同一问题:${pageContext.request.contextPath}不返回项目名称页面是否加载成功或是否出现异常?如果您遇到异常,请将其发布。并发布控制器类的其余部分。
<definition name="home" extends="app.base">
        <put-attribute name="title" value="Home" />
        <put-attribute name="body" value="/WEB-INF/jsp/home.jsp" />
        <put-list-attribute name="stylesheets_top" inherit="true">
            <add-attribute value="/resources/site/home/home.css" />
        </put-list-attribute>   
        <put-list-attribute name="javascripts_bottom" inherit="true">
            <add-attribute value="/resources/site/home/home.js" />
        </put-list-attribute>   
</definition>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<tiles:importAttribute name="stylesheets_top" />
<tiles:importAttribute name="javascripts_bottom" />
<!DOCTYPE html>
<html lang="en">

<head>

<title><tiles:insertAttribute name="title" /></title>

</head>
<body>
    <header>
        <!-- stylesheets top -->
        <c:forEach var="css" items="${stylesheets_top}">
            <link rel="stylesheet" type="text/css" href="<c:url value="${css}"/>">
        </c:forEach>
    </header>
    <div class="body">

        <tiles:insertAttribute name="body" />
    </div>
    <footer class="footer">
        <tiles:insertAttribute name="footer" />
    </footer>

</body>

<!-- scripts_bottom -->
<c:forEach var="script" items="${javascripts_bottom}">
    <script src="<c:url value="${script}"/>"></script>
</c:forEach>

</script>
</html>