Skip to content

Commit 9dedba6

Browse files
authored
Add a sample java web project (#14)
Co-authored-by: rick <linuxsuren@users.noreply.github.com>
1 parent 7d77b4a commit 9dedba6

4 files changed

Lines changed: 46 additions & 0 deletions

File tree

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<artifactId>demo-junit</artifactId>
77
<version>1.0.1-20170422</version>
88

9+
<packaging>war</packaging>
10+
911
<build>
1012
<plugins>
1113
<plugin>
@@ -33,6 +35,14 @@
3335
<version>2.3.20</version>
3436
</dependency>
3537

38+
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
39+
<dependency>
40+
<groupId>javax.servlet</groupId>
41+
<artifactId>servlet-api</artifactId>
42+
<version>2.5</version>
43+
<scope>provided</scope>
44+
</dependency>
45+
3646
<dependency>
3747
<groupId>junit</groupId>
3848
<artifactId>junit</artifactId>

src/main/java/hello/Web.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package hello;
2+
3+
import javax.servlet.http.HttpServlet;
4+
import javax.servlet.http.HttpServletRequest;
5+
import javax.servlet.http.HttpServletResponse;
6+
import java.io.IOException;
7+
import java.io.PrintWriter;
8+
9+
public class Web extends HttpServlet {
10+
public void doGet(HttpServletRequest req, HttpServletResponse res)
11+
throws IOException {
12+
res.setContentType("text/html");//setting the content type
13+
PrintWriter pw = res.getWriter();//get the stream to write the data
14+
15+
//writing html in the stream
16+
pw.println("<html><body>");
17+
pw.println("Welcome to servlet");
18+
pw.println("</body></html>");
19+
20+
pw.close();//closing the stream
21+
}
22+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<web-app>
2+
3+
<servlet>
4+
<servlet-name>sonoojaiswal</servlet-name>
5+
<servlet-class>hello.Web</servlet-class>
6+
</servlet>
7+
8+
<servlet-mapping>
9+
<servlet-name>sonoojaiswal</servlet-name>
10+
<url-pattern>/welcome</url-pattern>
11+
</servlet-mapping>
12+
13+
</web-app>

src/main/webapp/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello learn-pipeline-java

0 commit comments

Comments
 (0)