2014-09-27 86 views
0

我創建了一個項目春天+瓷磚,但我總是得到這個錯誤。我已閱讀了很多指南,但似乎無法解決問題。我在哪裏做錯了?謝謝錯誤(http狀態500)當我使用彈簧瓷磚

enter image description here

tiles.xml

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<!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="template" template="/WEB-INF/tiles/classic.jsp"> 
<put-attribute name="title" value="Tiles tutorial homepage" /> 
<put-attribute name="header" value="/WEB-INF/tiles/banner.jsp" /> 
<put-attribute name="menu" value="/WEB-INF/tiles/common_menu.jsp" /> 
<put-attribute name="body" value="/WEB-INF/tiles/home_body.jsp" /> 
<put-attribute name="footer" value="/WEB-INF/tiles/credits.jsp" /> 
</definition> 

<definition name="home" extends="template"> 
<put-attribute name="content" value="/WEB-INF/jsp/index.jsp"/> 
</definition> 
</tiles-definitions> 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>SpringMVCTiles</display-name> 

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

<servlet-mapping> 
<servlet-name>hellotiles</servlet-name> 
<url-pattern>/</url-pattern> 
</servlet-mapping> 

</web-app> 

hellotiles-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/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> 

<context:component-scan base-package="coreservlets"/> 

<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.tiles3.TilesConfigurer" > 
    <property name="definitions"> 
     <list> 
      <value>/WEB-INF/tiles.xml</value> 
     </list> 
    </property> 
    </bean> 

</beans> 

你好Controller.java

package coreservlets; 

import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

@Controller 
public class HelloController { 

@RequestMapping(value="/hello",method=RequestMethod.GET) 
public String stampaHello(ModelMap model){ 
    model.addAttribute("messaggio","Ciao scusate il ritardo"); 
    return "hello"; 
}//stampaHello 

@RequestMapping(value="/",method=RequestMethod.GET) 
public String visualizzaIndex(){ 
    return "index"; 
}//visualizzaIndex 

}//HelloController 

的hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
<!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=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<h1>${messaggio}</h1> 
</body> 
</html> 

的index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
<!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=ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<a href="/SpringMVCTiles/hello">Stampa ciao</a> 
</body> 
</html> 
+1

什麼' ViewResolver'應該處理'index'的名字?它沒有在瓷磚上定義..所以有錯誤的意義。 – 2014-09-27 18:51:24

+0

謝謝,我在tiles.xml中用name =「index」替換了name =「home」,並且我解決了問題 – Alex 2014-09-27 19:29:41

+1

我將分享它如何回覆。 – 2014-09-27 22:15:46

回答

1

什麼ViewResolver應該處理index名字?它尚未在tiles.xml上定義。所以有感應誤差

@Controller兩個返回的視圖名稱,他們是你好指數,但你的tiles.xml定義只有一個,它是