Home > Enterprise >  Creating Maven Project with Servlet in IntelliJ
Creating Maven Project with Servlet in IntelliJ

Time:09-09

I have been trying to create a servlet in intellij by following this tutorial: enter image description here enter image description here

When I run the project I can view "Hello World!" on both http://localhost:8080 and http://localhost:8080/DemoServlet. enter image description here enter image description here

However, I thought that you should only be able to view "Hello World!" at http://localhost:8080/DemoServlet and not at http://localhost:8080. I would like to know if this is the expected behavior for the program, or did I make a mistake in my configuration of the Servlet?

CodePudding user response:

This result is expected. The webapp context root displays the same text because there is src/main/webapp/index.jsp file provided by maven-archetype-webapp with the following:

<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

Since servlet and the index page print the same text, you were confused and thought that this text is also printed by the servlet, while it's actually an index page.

Notice that the text size is different. The index page uses <h2>, servlet code is using <h3>.

  • Related