2016-06-21 88 views
0

我讀了幾篇關於這個404錯誤的文章,但無濟於事。當我訪問這個基地址爲http://localhost:8080/chatapplication的項目時,我得到了404錯誤。我嘗試使用url http://localhost:8080/chatapplication/chat也得到了同樣的結果。我的代碼如下: -404沒有發現錯誤在彈簧mvc應用程序實現瓷磚

的web.xml

<!DOCTYPE web-app PUBLIC 
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd" > 

<web-app version="2.5" 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
    <display-name>Archetype Created Web Application</display-name> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 

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

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

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

</web-app> 

調度-servlet.xml中

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

    <context:component-scan base-package="com.abhishek.controllers" /> 

    <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> 

    </beans> 

tiles.xml

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

    <definition name="chat" extends="base.definition"> 
     <put-attribute name="title" value="Chat Application" /> 
     <put-attribute name="body" value="/WEB-INF/jsp/chat.jsp" /> 
    </definition> 
    </tiles-definitions> 

Controller類如下: -

package com.abhishek.controllers; 

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

/** 
* Created by CAN14 on 6/21/2016. 
*/ 
public class HelloWorldController { 
    @RequestMapping(value="/chat") 
    public String index() 
    { 
     System.out.println("**************"); 
     return "home"; 
    } 
} 

提前請help..thanks ..

回答

0

缺少HelloWorldController類@Controller註解。

+0

謝謝sir..I寫@Controller(一個很大的錯誤,它是),但隨後也找不到404錯誤..任何幫助,將不勝感激.. – Abhishek

0

爲您指定瓷磚視圖解析器因此,您可以定義其他視圖解析器,以便在您從控制器返回未映射的任何視圖時使用。您的控制器中的 您將返回「主頁」。其中沒有映射到tiles.xml中。 將其更改爲「聊天」,您將看到chat.jsp帶有頁眉和頁腳,因爲它被映射到tiles.xml中。

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

您還應該添加下面沒有瓦片地圖只有一個JSP

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

    <property name="order" value="1"/> 
</bean> 
相關問題