'Cannot create Servlet in IntelliJ Ultimate Edition

I cannot create servlet using New -> Servlet in IntelliJ IDEA. Of course it's Ultimate edition; I've marked src/main/java as source root directory but I still cannot create it automatically. Only option left is to create it manually as I did.



Solution 1:[1]

Open Project Settings and select Modules. You should see a list of all your project modules. The module where you want to create a Servlet in should have a Web Facet. If not, read enabling-web-application-support.

Every source route that contains your web application Java classes should be attached as source route to your web facet. That can be done on the web facet page.

After attaching all source routes the Create New Servlet option should be available the New menu.

Solution 2:[2]

I was experimenting a bit and came across a scenario, may be it help you. I created a directory main\java, which was created as a maven source directories as suggested by Intellij by default as shown in image.main\java Then i marked src as source directory and i do not get option to create new servlet under created java directory.
So in this particular case if you want to create servlet then first go to, "Mark directory as > Unmark as sources root". Now you can create servlet inside java directory as well.

Solution 3:[3]

I will just write my solution here. I had the same issue turned out all i needed to do was to scroll down once i right click on java source folder. The menu create new servlet should appear at the bottom below the data source section

Solution 4:[4]

It is possible that you are missing the servlet jar, if you are using the Idea Ultimate with maven then you can add the servlet dependency to it, I use embedded tomcat which adds the servlet itself

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-core</artifactId>
        <version>9.0.55</version>
    </dependency>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter
Solution 2 Anshu Shekhar
Solution 3 alpha oumar Diallo
Solution 4 ahtasham nazeer