wad-lab 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +2 -1
- package/package.json +1 -1
- package/templates/servlet-voter-eligibility/WEB-INF/VoterServlet.java +46 -0
- package/templates/servlet-voter-eligibility/WEB-INF/classes/VoterServlet.class +0 -0
- package/templates/servlet-voter-eligibility/WEB-INF/web.xml +20 -0
- package/templates/servlet-voter-eligibility/index.html +18 -0
package/bin/index.js
CHANGED
|
@@ -28,7 +28,7 @@ function copyDirRecursive(src, dest) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const templates = [
|
|
31
|
-
{ name: 'all (Unpack All
|
|
31
|
+
{ name: 'all (Unpack All 42 Templates)', value: 'all' },
|
|
32
32
|
{ name: 'vue-basics (ref, reactive, computed, v-model)', value: 'vue-basics' },
|
|
33
33
|
{ name: 'vue-props-emits (Parent/Child Component Communication)', value: 'vue-props-emits' },
|
|
34
34
|
{ name: 'vue-router (Parent Layout & Nested Children)', value: 'vue-router' },
|
|
@@ -45,6 +45,7 @@ const templates = [
|
|
|
45
45
|
{ name: 'servlet-jdbc (Tomcat + MySQL JDBC)', value: 'servlet-jdbc' },
|
|
46
46
|
{ name: 'servlet-flow (HelloServlet with GET/POST)', value: 'servlet-flow' },
|
|
47
47
|
{ name: 'servlet-session-tracking (HttpSession, Cookies, Redirect, URL Rewriting)', value: 'servlet-session-tracking' },
|
|
48
|
+
{ name: 'servlet-voter-eligibility (Name & Age Voting Eligibility Check)', value: 'servlet-voter-eligibility' },
|
|
48
49
|
{ name: 'springboot-mongo-crud (4-Layer REST API)', value: 'springboot-mongo-crud' },
|
|
49
50
|
{ name: 'springboot-mongo-aggregation ($group, $sum, $avg, $sort)', value: 'springboot-mongo-aggregation' },
|
|
50
51
|
{ name: 'springboot-mockmvc (Controller Tests)', value: 'springboot-mockmvc' },
|
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import java.io.IOException;
|
|
2
|
+
import java.io.PrintWriter;
|
|
3
|
+
import javax.servlet.ServletException;
|
|
4
|
+
import javax.servlet.http.HttpServlet;
|
|
5
|
+
import javax.servlet.http.HttpServletRequest;
|
|
6
|
+
import javax.servlet.http.HttpServletResponse;
|
|
7
|
+
|
|
8
|
+
public class VoterServlet extends HttpServlet {
|
|
9
|
+
|
|
10
|
+
@Override
|
|
11
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
12
|
+
throws ServletException, IOException {
|
|
13
|
+
response.sendRedirect("index.html");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Override
|
|
17
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
18
|
+
throws ServletException, IOException {
|
|
19
|
+
|
|
20
|
+
response.setContentType("text/html");
|
|
21
|
+
PrintWriter out = response.getWriter();
|
|
22
|
+
|
|
23
|
+
String name = request.getParameter("name");
|
|
24
|
+
String ageStr = request.getParameter("age");
|
|
25
|
+
|
|
26
|
+
out.println("<html><head><title>Voting Eligibility Result</title></head><body>");
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
int age = Integer.parseInt(ageStr.trim());
|
|
30
|
+
|
|
31
|
+
out.println("<h2>Hello " + name.trim() + "</h2>");
|
|
32
|
+
out.println("<p>Age: " + age + "</p>");
|
|
33
|
+
|
|
34
|
+
if (age >= 18) {
|
|
35
|
+
out.println("<h3 style='color:green;'>Eligible to vote</h3>");
|
|
36
|
+
} else {
|
|
37
|
+
out.println("<h3 style='color:red;'>Not able to vote</h3>");
|
|
38
|
+
}
|
|
39
|
+
} catch (Exception e) {
|
|
40
|
+
out.println("<p style='color:red;'>Invalid input</p>");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
out.println("<br><a href='index.html'>Back</a>");
|
|
44
|
+
out.println("</body></html>");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
4
|
+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
|
5
|
+
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
|
6
|
+
version="3.1">
|
|
7
|
+
|
|
8
|
+
<servlet>
|
|
9
|
+
<servlet-name>VoterServlet</servlet-name>
|
|
10
|
+
<servlet-class>VoterServlet</servlet-class>
|
|
11
|
+
</servlet>
|
|
12
|
+
<servlet-mapping>
|
|
13
|
+
<servlet-name>VoterServlet</servlet-name>
|
|
14
|
+
<url-pattern>/vote</url-pattern>
|
|
15
|
+
</servlet-mapping>
|
|
16
|
+
|
|
17
|
+
<welcome-file-list>
|
|
18
|
+
<welcome-file>index.html</welcome-file>
|
|
19
|
+
</welcome-file-list>
|
|
20
|
+
</web-app>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Voter Eligibility Checker</title>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<h2>Voter Eligibility Checker</h2>
|
|
8
|
+
<form action="vote" method="post">
|
|
9
|
+
<label>Name:</label><br>
|
|
10
|
+
<input type="text" name="name" required><br><br>
|
|
11
|
+
|
|
12
|
+
<label>Age:</label><br>
|
|
13
|
+
<input type="number" name="age" min="1" max="120" required><br><br>
|
|
14
|
+
|
|
15
|
+
<button type="submit">Check Eligibility</button>
|
|
16
|
+
</form>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|