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

时间:2015-01-11 07:36:41

标签: java spring-mvc http-status-code-404 autowired modelattribute

*大家好日子,朋友们!无论我尝试什么,我仍然会得到404错误消息,我真的不知道该怎么做..我试图在2天内修复它,仍然没有希望: 当我点击index.jsp上的链接,看到获取view.jsp页面时,我得到:  HTTP状态404 - /WEB-INF/circle.jsp

IDE:Intellij Idea 13

文件结构: 您可以通过以下链接查看我的文件结构: http://dl1.joxi.net/drive/0007/2131/485459/150110/cc3837ee1a.jpg

错误img: 您可以通过此链接查看我的错误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>

1 个答案:

答案 0 :(得分:0)

谢谢大家的支持。我,通过加入者,发现了错误:

MainController.java中的

我已经通过IDEA导入了org.springframework.web.portlet.ModelAndView; insted of import org.springframework.web.servlet.ModelAndView;现在它工作正常。感谢。