user2108383
user2108383

Reputation: 277

How to specify welcome file list in servlet web module 3.0

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

Answers (2)

Alexey Khamitov
Alexey Khamitov

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

Chetan Gole
Chetan Gole

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).set‌​ViewName("forward:/index.html");
    }
...
}

Or if you still want web.xml file, you can manually create it in Eclipse using following steps

  • Right Click on your web project
  • Select Java EE Tools
  • Select "Generate Deployment Descriptor Stub"

Upvotes: 0

Related Questions