diff --git a/.gitignore b/.gitignore index 981f55bb..2696c301 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ target tomcat.8080 +.classpath +.project +.settings/ diff --git a/src/main/java/launch/Main.java b/src/main/java/launch/Main.java index 13cb291e..3c5f5db9 100644 --- a/src/main/java/launch/Main.java +++ b/src/main/java/launch/Main.java @@ -1,7 +1,11 @@ package launch; import java.io.File; + +import org.apache.catalina.Context; import org.apache.catalina.startup.Tomcat; +import servlet.HelloServlet; + public class Main { public static void main(String[] args) throws Exception { @@ -18,7 +22,10 @@ public static void main(String[] args) throws Exception { tomcat.setPort(Integer.valueOf(webPort)); - tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath()); + Context ctx = tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath()); + //the context object can be used to configure your server with settings that would normally go in your context.xml + //ctx.setUseHttpOnly(true); + System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath()); tomcat.start(); diff --git a/src/main/java/servlet/HelloServlet.java b/src/main/java/servlet/HelloServlet.java index 34d5521c..c67382c6 100644 --- a/src/main/java/servlet/HelloServlet.java +++ b/src/main/java/servlet/HelloServlet.java @@ -2,6 +2,7 @@ import java.io.IOException; +import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.annotation.WebServlet; @@ -9,17 +10,26 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -@WebServlet( - name = "MyServlet", - urlPatterns = {"/hello"} - ) public class HelloServlet extends HttpServlet { + @Override + public void init() throws ServletException { + System.out.println("initializing HelloServlet"); + super.init(); + } + + @Override + public void init(ServletConfig config) throws ServletException { + System.out.println("initializing HelloServlet"); + super.init(); + } + + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletOutputStream out = resp.getOutputStream(); - out.write("hello heroku".getBytes()); + out.write("hello heroku!!!".getBytes()); out.flush(); out.close(); } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000..57f9abfd --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,18 @@ + + + + + hello + servlet.HelloServlet + + + + hello + /hello + + +