Reputation: 905
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.
Upvotes: 3
Views: 1645
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
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
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