IllegalSkillsException
IllegalSkillsException

Reputation: 905

WEB-INF/folder/.jsp gives 404

I have a spring MVC project and bunch of jsp files. When I try to access my jsp files in WEB-INF/views/ it gives me 404.

Screenshot for reference.

enter image description here

Upvotes: 3

Views: 1645

Answers (3)

yu yang Jian
yu yang Jian

Reputation: 7165

In my case, it is route need prefix /,

error 404:

@Result(name = "test", location="result.jsp")

works no error:

@Result(name = "test", location="/result.jsp")

Upvotes: 0

Ajit Soman
Ajit Soman

Reputation: 4074

You can't access jsp page inside WEB-INF folder directly. To access it you will need to create InternalResourceViewResolver bean for resolving path for your jsp pages:

@EnableWebMvc
@Configuration
public class AppConfig extends WebMvcConfigurerAdapter {
    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
        internalResourceViewResolver.setPrefix("/WEB-INF/views/");
        internalResourceViewResolver.setSuffix(".jsp");
        return internalResourceViewResolver;
    } 

And in your controller just return name of that jsp page:

@Controller
public class EmployeeController {

    @RequestMapping(value = "/add/employee", method = RequestMethod.GET)
    public String addEmployee(Model model) {
        return "addEmployee";
    }
}

Now hit URL: http://localhost:8181/SpringMVC_CRUD/add/employee

Upvotes: 5

Thilo
Thilo

Reputation: 262474

The stuff in WEB-INF is not exposed to the public URL space. You can only include/access it from other files. This is useful for templates and such (and of course, your compiled code also resides in there).

Move your public JSP outside of WEB-INF.

Upvotes: 2

Related Questions