2013-01-06 29 views
0

我收到以下消息,當我輸入/本地主機:8080/springapp2/Spring MVC安裝程序不工作 - 路徑問題?

HTTP Status 404 - Servlet spring is not available 

即使根網址無法正常運作。

這裏是我的文件...

的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" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id="WebApp_ID" version="2.5"> 
<servlet> 
    <servlet-name>spring</servlet-name> 
    <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>spring-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>spring</servlet-name> 
    <url-pattern>/*</url-pattern> 
</servlet-mapping> 

<display-name>Spring MVC Sample</display-name> 
</web-app> 

爲spring-servlet.xml

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

<context:annotation-config /> 
<context:component-scan base-package="org.nara.controllers"/> 

<bean id="jspViewResolver" 
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
    <property name="prefix" value="/" /> 
    <property name="suffix" value=".jsp" /> 
</bean>  
</beans> 

控制器類

package org.nara.controllers; 

import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
import org.springframework.web.servlet.ModelAndView; 

@Controller 
@RequestMapping (value="/") 
public class HelloWorldControllder { 

    public String HelloWorld() { 
    return "hello"; 
} 

@RequestMapping(value="/greetme", method = RequestMethod.GET) 
public ModelAndView handlePOST(HttpServletRequest request, HttpServletResponse response) { 
    ModelAndView mav = new ModelAndView("index.jsp"); 
    mav.addObject("Greeting", "Hello you"); 
    return mav; 
} 
} 
+0

你有classpath中的彈簧罐嗎?從tomcat日誌中發佈異常跟蹤。 – Subin

+0

不是罐子的問題。一切都很好。我解決了它。 –

回答

0

我得到這個解決。我改變了一些事情。

  • 更改URL模式/
  • 新增春天表情罐子類路徑
  • 有與contextConfigLocation的URL的問題。我更新了它

現在它就像一個魅力。 希望這可以幫助別人。