2017-09-06 45 views
0

我正在嘗試開發我的第一個spring mvc應用程序並獲得上述錯誤。 我搜索了同樣例外的解決方案,但找不到任何解決方案。我總是在Spring mvc應用程序中得到HTTP-404錯誤

,這裏是我的web.xml

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

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

MVC-調度-servlet.xml文件

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 

    <context:component-scan base-package="m"/> 
<mvc:default-servlet-handler /> 


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

    </property> 
    <property name="suffix"> 
    <value>.jsp</value> 
    </property> 
    </bean> 
</beans> 

的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 charset="ISO-8859-1"> 
<title>Insert title here</title> 
</head> 
<body> 
<form action="/Hello.ds"> 
NAME : <input type="text" name="hello"> 
<input type="submit" value="OK"> 
</form> 
</body> 
</html> 

控制器

@org.springframework.stereotype.Controller 
public class jnk { 
@RequestMapping("/Hello") 
    public ModelAndView handleRequest(HttpServletRequest r,HttpServletResponse res) throws Exception{ 

     String name=r.getParameter("name"); 
     ModelAndView m=new ModelAndView("success"); 
     m.addObject("MSG", name); 
     return m; 
    } 

} 

我的JSP文件駐留在WEB-INF/ 目錄下

包名是:M

+0

我注意到你正在使用JSP。您可能想要從Spring Boot中查看這個示例項目,它演示了一個基本的JSP配置。 https://github.com/spring-projects/spring-boot/tree/v1.5.6.RELEASE/spring-boot-samples/spring-boot-sample-web-jsp/src/main –

回答

1

控制器暴露了一個名爲/Hello(參見:@RequestMapping("/Hello"))映射,但你的表格試圖提交/Hello.ds(見<form action="/Hello.ds">)。

+0

我chamge @RequestMapping(「/Hello「)到@RequestMapping(」/ Hello.ds「),但它仍然不起作用,並提供錯誤HTTP狀態404 - /Hello.ds描述請求的資源不可用。 –

相關問題