Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
target
tomcat.8080
.classpath
.project
.settings/
9 changes: 8 additions & 1 deletion src/main/java/launch/Main.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/servlet/HelloServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
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();
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>servlet.HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

</web-app>