Skip to content

Commit c3a5619

Browse files
author
Matheus Vieira
committed
java servlet initial structure
0 parents  commit c3a5619

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

README.md

40 Bytes

java-rate-limit

pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>mathunes</groupId>
5+
<artifactId>rate-limit</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>war</packaging>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>javax.servlet</groupId>
12+
<artifactId>javax.servlet-api</artifactId>
13+
<version>4.0.1</version>
14+
<scope>provided</scope>
15+
</dependency>
16+
</dependencies>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-war-plugin</artifactId>
23+
<version>3.2.3</version>
24+
<configuration>
25+
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
26+
</configuration>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
</project>

src/main/java/MyServlet.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import java.io.IOException;
3+
import javax.servlet.ServletException;
4+
import javax.servlet.annotation.WebServlet;
5+
import javax.servlet.http.HttpServlet;
6+
import javax.servlet.http.HttpServletRequest;
7+
import javax.servlet.http.HttpServletResponse;
8+
9+
@WebServlet("/MyServlet")
10+
public class MyServlet extends HttpServlet {
11+
12+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
13+
response.setContentType("application/json");
14+
String json = "{\"status\": \"server running\"}";
15+
response.getWriter().write(json);
16+
}
17+
18+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
19+
this.doGet(request, response);
20+
}
21+
22+
}

src/main/webapp/WEB-INF/web.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
5+
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6+
version="3.0">
7+
<display-name>rate-limit</display-name>
8+
9+
<servlet>
10+
<servlet-name>MyServlet</servlet-name>
11+
<servlet-class>MyServlet</servlet-class>
12+
</servlet>
13+
14+
<servlet-mapping>
15+
<servlet-name>MyServlet</servlet-name>
16+
<url-pattern>/myservlet</url-pattern>
17+
</servlet-mapping>
18+
</web-app>

0 commit comments

Comments
 (0)