Spring MVC @Autowired 和 @ModelAttribute HTTP 状态 404 - /WEB-INF/circle。jsp

Spring MVC @Autowired and @ModelAttribute HTTP Status 404 - /WEB-INF/circle.jsp

*朋友们,大家好!无论我尝试什么,我仍然收到 404 错误消息,我真的不知道该怎么做。我在这 2 天内尝试修复它,但仍然无望: 当我点击 index.jsp 上的 link,而不是获取 view.jsp 页面时,我得到: HTTP 状态 404 - /WEB-INF/circle.jsp

IDE:Intellij 创意 13

文件结构: 你可以通过这个 link 查看我的文件结构: http://dl1.joxi.net/drive/0007/2131/485459/150110/cc3837ee1a.jpg

错误图片: 你可以通过这个 link 查看我的错误 img: http://dl2.joxi.net/drive/0007/2131/485459/150110/0c70f50d3c.jpg

MainController.java

@Controller
public class MainController {
@Autowired
@Qualifier("rectanglePoint")
private Shape rectanglePoint;

@Autowired
@Qualifier("rectangle")
private Shape rectangle;

@Autowired
@Qualifier("circle")
private Shape circle;


public MainController(){

}
@RequestMapping(value = "/rectanglepoint", method = RequestMethod.GET)
public ModelAndView rectanglePoint(){
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("message", rectanglePoint.square());
    modelAndView.setViewName("view");
return modelAndView;
}

@RequestMapping(value = "/rectangle", method = RequestMethod.GET)
public ModelAndView rectangle(){
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("message", rectangle.square());
    modelAndView.setViewName("view");
    return modelAndView;
}

@RequestMapping(value = "/circle", method = RequestMethod.GET)
public ModelAndView circle(){
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("message", circle.square());
    modelAndView.setViewName("view");
    return modelAndView;
}
}    

springframeworkmvc-servlet.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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-3.1.xsd
   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3-1.xsd">

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

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/" />
    <property name="suffix" value=".jsp"/>
</bean>

<bean id="rectanglePoint" class="classes.RectanglePoint">
<constructor-arg index="0" ref="pointleft"/>
<constructor-arg index="1" ref="pointright"/>
</bean>
<bean id="circle" class="classes.Circle">
    <constructor-arg index="0" value="5"/>
</bean>
<bean id="rectangle" class="classes.Rectangle ">
    <constructor-arg index="0" value="2"/>
    <constructor-arg index="1" value="5"/>
</bean>

<bean id="pointleft" class="classes.Point">
    <constructor-arg name="x" value="1"/>
    <constructor-arg name="y" value="2"/>
</bean>
<bean id="pointright" class="classes.Point">
   <property name="x" value="2"/>
    <property name="y" value="1"/>
</bean>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_3_0.xsd"
     version="3.0">
<display-name>springframework</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/springframeworkmvc-servlet.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>springframeworkmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>springframeworkmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

view.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
${message}
</body>
</html>

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head>
<body>
<a href="/circle.do">link</a>
</body>
</html>

感谢大家的支持。我无意中发现了错误:

在MainController.java我用IDEA导入建议org.springframework.web.portlet.ModelAndView; insted 导入 org.springframework.web.servlet.ModelAndView;现在它工作正常。谢谢。