Spring MVC 404错误 [英] Spring MVC 404 error

查看:101
本文介绍了Spring MVC 404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我快疯了,不明白问题出在什么地方:

I'm going crazy and can't understand what the problem is:

我具有以下结构:

SpringMVC
  +WebContent
      -web-inf
        -web.xml
        -springMVC-servlet.xml
      -index.jsp
      -security
           -login.jsp 

web.xml

<display-name>springMVC</display-name> 
<servlet> 
  <servlet-name>springMVC</servlet-name> 
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping>
  <servlet-name>springMVC</servlet-name>
  <url-pattern>*.html</url-pattern>
</servlet-mapping> 
  <servlet-mapping>
  <servlet-name>springMVC</servlet-name>
  <url-pattern>*.do</url-pattern> 
</servlet-mapping> 
<servlet-mapping> 
  <servlet-name>springMVC</servlet-name> 
  <url-pattern>/index.html</url-pattern>
</servlet-mapping>
<welcome-file-list> 
  <welcome-file>index.html</welcome-file> 
</welcome-file-list>

springMVC-servlet.xml

springMVC-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xsi:schemaLocation=" http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context-3.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" 
        xmlns:mvc="http://www.springframework.org/schema/mvc"  
        xmlns:aop="http://www.springframework.org/schema/aop" 
        xmlns:context="http://www.springframework.org/schema/context" 
        xmlns:p="http://www.springframework.org/schema/p" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns="http://www.springframework.org/schema/beans"> 

    <context:annotation-config/> 
    <context:component-scan base-package="com.vanilla.springMVC"/> 

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

</beans>

我的控制器:

package com.vanilla.springMVC;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.portlet.ModelAndView;

@Controller
public class DefaultController {

    @RequestMapping(value="/index.html", method=RequestMethod.GET)
    public ModelAndView index(){
        ModelAndView mv = new ModelAndView("index");
        return mv;
    }

    @RequestMapping(value="/login.html", method=RequestMethod.GET)
    public ModelAndView loginPage(){
        ModelAndView mv = new ModelAndView("/security/login");
        return mv;
    }
}

我没有问题可以导航到/index.html

I have no problem to navigate to /index.html

http://localhost:8080/SpringMVC/index.html 工作完美.

但是当我导航到 http://localhost:8080/SpringMVC/login.html 我有404错误.

however when I'm navigating to http://localhost:8080/SpringMVC/login.html i have 404 error.

HTTP Status 404 - /SpringMVC/login.jsp    
type Status report
message /SpringMVC/login.jsp
description The requested resource (/SpringMVC/login.jsp) is not available.

我不想将login.jsp与index.jsp移到同一级别,但是为什么会有这个问题?

I don't want to move login.jsp on the same level as index.jsp, but why do I have this problem?

推荐答案

HTTP 404表示找不到资源.

HTTP 404 means that the resource is not found.

  • 这意味着找不到控制器或直接访问的资源(如CSS文件)
  • 它确实意味着未找到控制器中引用的JSP(这将是500 Internal Server Error)
  • This means the controller or a direct accessed resource (like a CSS file) is not found
  • It does NOT mean that the JSP referred in the controller is not found (this would be a 500 Internal Server Error)

HTTP状态404-/SpringMVC/login.jsp

HTTP Status 404 - /SpringMVC/login.jsp

您似乎发送了HTTP请求/SpringMVC/login.jsp,但是您的控制器方法已绑定到.html,因此您需要将HTTP请求更改为/SpringMVC/login.html

It looks like that you send a HTTP request /SpringMVC/login.jsp but your controller method is bound to .html, so you need to change your HTTP request to /SpringMVC/login.html

由于名称(登录)的原因,您的Spring Security配置可能不正确.

这篇关于Spring MVC 404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆