File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
web-modules/jakarta-servlets-2
src/main/java/com/baeldung/jakartaeetomcat Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 3131 <groupId >jakarta.servlet</groupId >
3232 <artifactId >jakarta.servlet-api</artifactId >
3333 <version >${jakarta.servlet-api.version} </version >
34+ <scope >provided</scope >
3435 </dependency >
3536 <dependency >
3637 <groupId >jakarta.servlet.jsp</groupId >
8990 </webApp >
9091 </configuration >
9192 </plugin >
93+ <plugin >
94+ <groupId >org.apache.maven.plugins</groupId >
95+ <artifactId >maven-compiler-plugin</artifactId >
96+ <configuration >
97+ <source >21</source >
98+ <target >21</target >
99+ </configuration >
100+ </plugin >
92101 </plugins >
93102 </build >
94103
Original file line number Diff line number Diff line change 1+ package com .baeldung .jakartaeetomcat ;
2+
3+ import java .io .IOException ;
4+ import java .io .PrintWriter ;
5+ import java .time .LocalDateTime ;
6+
7+ import jakarta .servlet .ServletException ;
8+ import jakarta .servlet .annotation .WebServlet ;
9+ import jakarta .servlet .http .HttpServlet ;
10+ import jakarta .servlet .http .HttpServletRequest ;
11+ import jakarta .servlet .http .HttpServletResponse ;
12+
13+ @ WebServlet (name = "CurrentDateAndTime" , urlPatterns = { "/date-time" })
14+ public class CurrentDateAndTime extends HttpServlet {
15+
16+ LocalDateTime currentDate = LocalDateTime .now ();
17+
18+ protected void processRequest (HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
19+ response .setContentType ("text/html;charset=UTF-8" );
20+ currentDate = LocalDateTime .now ();
21+
22+ try (PrintWriter out = response .getWriter ()) {
23+ out .printf ("""
24+ <html>
25+ <head> <title> Current Date And Time </title> </head>
26+ <body> <h2> Servlet current date and time at %s </h2> <br/> Date and Time %s </body>
27+ </html>
28+ """ , request .getContextPath (), currentDate );
29+ }
30+ }
31+
32+ @ Override
33+ protected void doGet (HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
34+ processRequest (request , response );
35+ }
36+
37+
38+
39+ }
40+
You can’t perform that action at this time.
0 commit comments