Reputation: 277
I am creating servlet with web module 3.0, and I see there is no web.xml created along with that, say if I have multiple jsp pages in my project, how can I specify the welcome file, do we have any annotations for mentioning welcome file?
Upvotes: 1
Views: 810
Reputation: 51
You can combine the use of annotations @WebServlet and web.xml file.
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
...
</welcome-file-list>
</web-app>
Just create it manually.
Upvotes: 1
Reputation: 743
Yes you can have a Java file to mention the welcome files
@EnableWebMvc
@Configuration
@ComponentScan("com.springapp.mvc")
public class MvcConfig extends WebMvcConfigurerAdapter {
...
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/*.html").addResourceLocations("/WEB-INF/pages/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setStatusCode(HttpStatus.MOVED_PERMANENTLY).setViewName("forward:/index.html");
}
...
}
Or if you still want web.xml file, you can manually create it in Eclipse using following steps
Upvotes: 0