diff options
Diffstat (limited to 'maven/03-hello2-form-submission-webapp/src')
3 files changed, 56 insertions, 0 deletions
diff --git a/maven/03-hello2-form-submission-webapp/src/main/java/lk/ac/pdn/ceit/hello/PostExampleServlet.java b/maven/03-hello2-form-submission-webapp/src/main/java/lk/ac/pdn/ceit/hello/PostExampleServlet.java new file mode 100644 index 0000000..f6ba0c6 --- /dev/null +++ b/maven/03-hello2-form-submission-webapp/src/main/java/lk/ac/pdn/ceit/hello/PostExampleServlet.java @@ -0,0 +1,35 @@ + +package lk.ac.pdn.ceit.hello; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +@WebServlet("/submitForm") +public class PostExampleServlet extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/html;charset=UTF-8"); + String userName = request.getParameter("name"); + + try (PrintWriter out = response.getWriter()) { + out.println("<!DOCTYPE html>"); + out.println("<html>"); + out.println("<head>"); + out.println("<title>Servlet Post Example Response</title>"); + out.println("</head>"); + out.println("<body>"); + out.println("<h1>Thank you for your submission, " + (userName != null && !userName.isEmpty() ? userName : "Guest") + "!</h1>"); + out.println("<p>Method used: " + request.getMethod() + "</p>"); + out.println("</body>"); + out.println("</html>"); + } + } +}
\ No newline at end of file diff --git a/maven/03-hello2-form-submission-webapp/src/main/webapp/WEB-INF/web.xml b/maven/03-hello2-form-submission-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9f88c1f --- /dev/null +++ b/maven/03-hello2-form-submission-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ +<!DOCTYPE web-app PUBLIC + "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd" > + +<web-app> + <display-name>Archetype Created Web Application</display-name> +</web-app> diff --git a/maven/03-hello2-form-submission-webapp/src/main/webapp/index.jsp b/maven/03-hello2-form-submission-webapp/src/main/webapp/index.jsp new file mode 100644 index 0000000..77dd3d6 --- /dev/null +++ b/maven/03-hello2-form-submission-webapp/src/main/webapp/index.jsp @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> +<head> + <title>Jakarta EE 11 Servlet Post Example</title> +</head> +<body> + <h1>Enter your name</h1> + <form action="submitForm" method="POST"> + <label for="name">Name:</label> + <input type="text" id="name" name="name"> + <input type="submit" value="Submit"> + </form> +</body> +</html>
\ No newline at end of file |
