2015-08-08 79 views
0

考慮以下Controller沒有映射發現的Index.html

@Controller 
public class HomeController { 

@RequestMapping(value="/") 
public ModelAndView home() { 
    ModelAndView model = new ModelAndView("index"); 
    return model; 
} 

這是我servlet-context.xml

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/views/" /> 
    <property name="suffix" value=".html" /> 
</bean> 

這是我web.xml

<!-- Processes application requests --> 
<servlet> 
    <servlet-name>appServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

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

每次我點擊網址我收到此消息:

Aug 08, 2015 10:59:47 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/MeraComputer/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet' Aug 08, 2015 10:59:48 PM org.springframework.web.servlet.PageNotFound noHandlerFound WARNING: No mapping found for HTTP request with URI [/MeraComputer/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet'

我的文件夾結構也不錯,我想,

Folder Structure

+0

顯示您的應用程序的樹結構 –

+0

單擊文件夾結構鏈接..您將會看到... – anonymous

+0

可能是這個文件'servlet-context.xml'的東西 – ACV

回答

0

我認爲靜態的html文件將沒有意見工作。請求正在轉發到視圖,即/MeraComputer/WEB-INF/views/index.html,並且因爲它是一個靜態文件而不是請求處理程序,您可能會收到警告。

應該以不同的方式處理靜態文件。 This is一個類似的帖子,我認爲,這可能有所幫助。

+0

我將Html更改爲jsp。它的功能就像魅力一樣。謝謝。 – anonymous