Spring mvc 创建完项目测试的时候前台404,后台没有错误信息这是咋了

好吧我输了 发布于 06/19 15:36
阅读 176
收藏 0

前天遇到一个问题,springmvc创建的项目测试的时候前台404,后台没有错误输出,奇了怪了......

 

这是WEB-INF下的xml文件

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

  <display-name>SpringMVC05</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>

  <servlet>

    <servlet-name>webxml</servlet-name>

    <servlet-class>

  org.springframework.web.servlet.DispatcherServlet

  </servlet-class>

    <init-param>

      <param-name>contextConfigLocation</param-name>

      <param-value>classpath:applicationContext.xml</param-value>

    </init-param>

    <load-on-startup>1</load-on-startup>

  </servlet>

  <servlet-mapping>

    <servlet-name>webxml</servlet-name>

    <url-pattern>*.do</url-pattern>

  </servlet-mapping>

</web-app>

 

这是我的Controller   在src的controller包下面

package controller;

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

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class HelloController implements Controller{

    
    public ModelAndView handleRequest(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
        System.out.println("Controller");
        return new ModelAndView("hello");
    
    }
}
 

这是spring的配置文件applicationContext.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:util="http://www.springframework.org/schema/util"  

xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd

http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd

http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

 

<context:component-scan base-package="controller.HelloController"/>

 

<!-- HandlerMappings -->

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

<property name="mappings">

<props>

<prop key="/hello.do">controller</prop>

</props>

</property>

</bean>

 

<!-- Controller -->

<bean id="controller" class="controller.HelloController"></bean>

 

<!-- View 决定了用哪一个视图显示数据-->

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/"></property>

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

</bean>

 

</beans> 

 

 

加载中
0
将军_General
将军_General

都404了,后台一定没有错误信息啊, 你的看看你的控制器是不是没加注解啊之类的问题,总之我感觉就是你没有将你要访问的controller 正确的注入的spring, 或者是中间被拦截了

0
hakcker5
hakcker5

springmvc没用@RequestMapping?

0
孤星闵月
孤星闵月
我还没做过不用注解的springMVC,
返回顶部
顶部