简体   繁体   中英

404 resolving view in spring servlet

I have a Spring (4) MVC servlet running on Tomcat 8 in Eclipse. When I start tomcat, there are no errors in the console and all the correct request mappings for my controllers are logged. 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:

message /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/ . 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.

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

Assumptions:

  • a mapping to root/WebContent is not provided in Web deployment assembly.

  • a mapping to /src/main/webapp is present in Web deployment assembly.

  • your eclipse is using maven war plugin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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