Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_weekendowa_20221008
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_weekendowa_20221008
Commits
442e7394
Commit
442e7394
authored
Oct 09, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pierwszy przykład zwracania HTML
parent
ac67a3bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
KtoraGodzinaHtml.java
PC23-Serwlety/src/main/java/podstawy/KtoraGodzinaHtml.java
+34
-0
Ping.java
PC23-Serwlety/src/main/java/podstawy/Ping.java
+11
-0
No files found.
PC23-Serwlety/src/main/java/podstawy/KtoraGodzinaHtml.java
0 → 100644
View file @
442e7394
package
podstawy
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.time.LocalDateTime
;
import
javax.servlet.ServletException
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
@WebServlet
(
"/godzina"
)
public
class
KtoraGodzinaHtml
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
LocalDateTime
dt
=
LocalDateTime
.
now
();
response
.
setContentType
(
"text/html"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
"<!DOCTYPE html>"
);
out
.
println
(
"<html><head>"
);
out
.
println
(
"<title>Bieżący czas</title>"
);
out
.
println
(
"</head>"
);
out
.
println
(
"<body>"
);
out
.
println
(
"<p>Dzisiejsza data: <strong style='color:blue'>"
+
dt
.
toLocalDate
()
+
"</strong></p>"
);
out
.
println
(
"<p>Bieżący czas: <strong style='color:magenta'>"
+
dt
.
toLocalTime
()
+
"</strong></p>"
);
out
.
println
(
"</body></html>"
);
}
}
PC23-Serwlety/src/main/java/podstawy/Ping.java
View file @
442e7394
...
@@ -17,7 +17,18 @@ public class Ping extends HttpServlet {
...
@@ -17,7 +17,18 @@ public class Ping extends HttpServlet {
public
Ping
()
{
public
Ping
()
{
System
.
out
.
println
(
"Powstaje obiekt serwletu"
);
System
.
out
.
println
(
"Powstaje obiekt serwletu"
);
}
}
@Override
public
void
init
()
{
System
.
out
.
println
(
"init"
);
}
@Override
public
void
destroy
()
{
System
.
out
.
println
(
"destroy"
);
}
@Override
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
/* Gdy uruchamiamy / wgrywamy aplikację, serwer tworzy obiekt tej klasy (serwletu, np. Ping).
/* Gdy uruchamiamy / wgrywamy aplikację, serwer tworzy obiekt tej klasy (serwletu, np. Ping).
* Gdy przychodzi zapytanie HTTP typu GET skierowane pod adres tego serwletu (np. /Ping),
* Gdy przychodzi zapytanie HTTP typu GET skierowane pod adres tego serwletu (np. /Ping),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment