I just want to run the HelloServlet by the url: http://localhost:8080/HelloServlet. but it shows the requested resource (/HelloServlet) is not available. I use tomcat 7.0.28.
Running from localhost:8080, it shows the page.
HelloServlet code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet("/HelloServlet")
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello</H1>\n" +
"</BODY></HTML>");
}
}
What is the issue?
To get this URL, you would have to deploy the webapp as the root webapp. AFAIR, you just need to name the generated war ROOT.war to do that. Otherwise, the app is deployed under a context path, which is by default the name of the war file. So if your war if hello.war, the URL should be