2015-05-01 83 views
0

我在我的項目中添加了瓷磚,但它不起作用。我添加了頁腳。但是頁腳和標題不會顯示在輸出中。我只得到輸出瓷磚不能與彈簧一起使用

hello ........................... 

但我沒有得到輸出中的頁腳內容。我如何讓瓷磚工作?提前致謝。

在我的佈局文件夾中,我有classic.jsp和footer.jsp。

classic.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> 
<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title><tiles:getAsString name="title" /></title> 
</head> 
<body> 

    <tiles:insertAttribute name="body" /> 
    <br> 
    <br> 
    <tiles:insertAttribute name="footer" /> 

</body> 
</html> 

footer.jsp中

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 

&copy; Test 

的index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 

hello ........................... 

調度-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:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> 

    <context:component-scan base-package="cz.jiripinkas.jba.controller" /> 

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

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

    <bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

</beans> 

general.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE tiles-definitions PUBLIC 
     "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" 
     "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"> 
<tiles-definitions> 
    <definition name="common" template="/WEB-INF/layout/classic.jsp"> 
     <put-attribute name="footer" value="/WEB-INF/layout/footer.jsp" /> 
    </definition> 

    <definition name="index" extends="common"> 
     <put-attribute name="title" value="Java Blog Aggregator" /> 
     <put-attribute name="body" value="/WEB-INF/jsp/index.jsp" /> 
    </definition> 

</tiles-definitions> 

和索引控制器

package cz.jiripinkas.jba.controller; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 

@Controller 
public class IndexController { 

    @RequestMapping("/index") 
    public String index() { 
     return "index"; 
    } 
} 
+0

我的代碼在這裏https://github.com/shiblybcc/blog-aggregator – asdfkjasdfjk

回答

0

沒有爲我工作。我不得不將我的apache磁貼版本升級到當前版本。

0
@RequestMapping("/index") 
    public ModelAndView index() { 
     return new ModelAndView("index") ; 
    } 

所以rteurn代替字符串的ModelAndView中。

+0

作爲'String'返回也應該有效。 – coderz

0

我建議的代碼應改爲此

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

<bean id= "viewResolver" 
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
<property name="prefix" value="/WEB-INF/jsp/" /> 
-1

您返回IndexController錯誤值,您IndexController引導到index.jsp,那就是:

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 

hello ........................... 

它只是輸出hello ...........................,對不對?

嘗試:

@Controller 
public class IndexController { 

    @RequestMapping("/classic") 
    public String classic() { 
     return "classic"; 
    } 
}