简体   繁体   English

Spring Servlet中的404解析视图

[英]404 resolving view in spring servlet

I have a Spring (4) MVC servlet running on Tomcat 8 in Eclipse. 我有一个在Eclipse的Tomcat 8上运行的Spring(4)MVC servlet。 When I start tomcat, there are no errors in the console and all the correct request mappings for my controllers are logged. 当我启动tomcat时,控制台中没有错误,并且记录了控制器的所有正确请求映射。 If I try to access localhost:8080/app/login my controller method executes (checked via debugging), but I get a 404 page with the following: 如果我尝试访问localhost:8080/app/login则会执行我的控制器方法(通过调试进行检查),但是我得到一个带有以下内容的404页面:

message /app/WEB-INF/jsp/login.jsp 消息/app/WEB-INF/jsp/login.jsp

description The requested resource is not available. 描述所请求的资源不可用。

My project has the following directory structure: 我的项目具有以下目录结构:

project-root
 |-src
 |-WebContent
    |-WEB-INF
       |-jsp
          |-login.jsp

My configuration class: 我的配置类:

@EnableWebMvc
@Configuration
@ComponentScan(basePackages = "com.example")
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void configureViewResolvers(final ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/jsp/", ".jsp").viewClass(JstlView.class);
    }
    //Other stuff
}

Controller: 控制器:

@Controller
@RequestMapping("/login")
public class AuthnRequestController {
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ModelAndView getLoginPage() {
        return new ModelAndView("login");
    }
    //Other stuff
}

The application was working fine in the past, but I was screwing around with my workspace/projects working on something else, and am unable to get this working again now that I'm coming back to it. 过去,该应用程序运行良好,但是我正在处理我的工作空间/项目在其他方面的工作,现在我又回到了工作状态,因此无法使其再次正常工作。

AFAIK, By default in a maven war project the jsp files are expected under /src/main/resources/ . AFAIK,默认情况下,在Maven战争项目中,jsp文件应位于/src/main/resources/ Since you have given a jsp file prefix of /WEB-INF/jsp/ in your config, please try moving the jsp files to the below location. 由于您在配置中给了jsp文件前缀/WEB-INF/jsp/ ,因此请尝试将jsp文件移动到以下位置。

/src/main/webapp/WEB-INF/jsp/

Assumptions: 假设:

  • a mapping to root/WebContent is not provided in Web deployment assembly. Web部署程序集中未提供到root/WebContent的映射。

  • a mapping to /src/main/webapp is present in Web deployment assembly. Web部署程序集中存在到/src/main/webapp的映射。

  • your eclipse is using maven war plugin 您的日食正在使用maven war plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM