2017-09-06 84 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描述请求的资源不可用。 –

相关问题