-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathInstructionsToCreateApp.txt
140 lines (114 loc) · 3.36 KB
/
InstructionsToCreateApp.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
Install dependencies
Insall java
https://phoenixnap.com/kb/install-java-windows
Install maven
https://phoenixnap.com/kb/install-maven-windows
https://www.digitalocean.com/community/tutorials/install-maven-mac-os
Install tomcat
https://phoenixnap.com/kb/install-tomcat-windows
don't do the configurations. (do till step 3)
mvn archetype:generate -DgroupId=com.staragile.test -DartifactId=test -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
copy the following in pom.xml
--------------------
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>test</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<attachClasses>true</attachClasses>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
--------------------
add index.jsp in src/main/webapp folder
------------------------
<html>
<head>
<meta charset="ISO-8859-1">
<title>Hello World web application</title>
</head>
<body>
<h1>Thanks a lot for being so patient through the session!</h1>
<form action="helloServlet" method="post">
Enter your name: <input type="text" name="username" size="20">
<input type="submit" value="Call Servlet" />
</form>
</body>
</html>
----------------
add HelloServlet.java to src/main/java
package com.test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class HelloServlet
*/
@WebServlet("/helloServlet")
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String yourName = request.getParameter("username");
if(yourName ==null){
yourName = "Vilas";
}
PrintWriter writer = response.getWriter();
writer.println("<h1>Hello " + yourName + "</h1>");
writer.close();
}
}