I have a simple web app using Servlet 3.0 using Tomcat 7.0.25 and deploying the app as a war (mywebapp.war).
The war structure is as below:
mywebapp/index.html
mywebapp/META-INF/MANIFEST.MF
mywebapp/WEB-INF/classes/org/iq/adapter/ServerAdapter.class
index.html
:
<html>
<head>
<title>my web app</title>
</head>
<body>
<h1>Your server is Up and Running</h1>
</body>
</html>
ServerAdapter.java
:
package org.iq.adapter;
@WebServlet(name="ServerAdapter", urlPatterns="/adapter/*")
public class ServerAdapter extends HttpServlet {
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println(this.getClass()+"::doGet called");
}
@Override
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println(this.getClass()+"::doPost called");
}
}
When I try to access mywebapp from browser using the below links:
localhost:8080/mywebapp
- I get a blank screen, index.html is not rendered - WHY? I guess since welcome file is not mentioned as I am not using a web.xmllocalhost:8080/mywebapp/index.html
- I get a blank screen, index.html is still not rendered - WHY? I am lostlocalhost:8080/mywebapp/adapter
- I get a blank screen, but I get the sysout on the server console as "class org.iq.adapter.ServerAdapter::doGet called" - as expected
Create a web.xml file in Web-INF folder like the following and add index.html in welcome files list