Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230928
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
javab_20230928
Commits
32adc303
Commit
32adc303
authored
Oct 17, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ping
parent
59cf756f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
Ping.java
PC24-Serwlety/src/main/java/podstawy/Ping.java
+52
-0
index.html
PC24-Serwlety/src/main/webapp/index.html
+1
-0
No files found.
PC24-Serwlety/src/main/java/podstawy/Ping.java
0 → 100644
View file @
32adc303
package
podstawy
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.time.LocalDateTime
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.annotation.WebServlet
;
import
jakarta.servlet.http.HttpServlet
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
@WebServlet
(
"/ping"
)
public
class
Ping
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
public
Ping
()
{
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
{
/* 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),
* serwer wywołuje metodę doGet i w obiekcie request przekazuje nam informację o zapytaniu (adres, parametry, w przypadku metody POST także treść),
* natomiast obiekt response dostajemy po to, aby za jego pomocą wygenerować odpowiedź.
*/
String
addr
=
request
.
getRemoteAddr
();
int
port
=
request
.
getRemotePort
();
String
userAgent
=
request
.
getHeader
(
"User-Agent"
);
LocalDateTime
dt
=
LocalDateTime
.
now
();
System
.
out
.
println
(
dt
+
": zapytanie z adresu "
+
addr
+
":"
+
port
+
"\nz przeglądarki "
+
userAgent
);
response
.
setContentType
(
"text/plain"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
dt
+
": piszesz z adresu "
+
addr
+
":"
+
port
);
out
.
println
(
userAgent
);
}
}
PC24-Serwlety/src/main/webapp/index.html
View file @
32adc303
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
<h1>
Spis treści
</h1>
<h1>
Spis treści
</h1>
<ul>
<ul>
<li><a
href=
"hello"
>
hello
</a>
- PierwszySerwlet
</li>
<li><a
href=
"hello"
>
hello
</a>
- PierwszySerwlet
</li>
<li><a
href=
"ping"
>
ping
</a></li>
<li><a
href=
"godzina"
>
która godzina
</a></li>
<li><a
href=
"godzina"
>
która godzina
</a></li>
<li><a
href=
"rozmowa"
>
rozmowa
</a>
- przykład formularza
</li>
<li><a
href=
"rozmowa"
>
rozmowa
</a>
- przykład formularza
</li>
<li><a
href=
"kalkulator"
>
kalkulator
</a></li>
<li><a
href=
"kalkulator"
>
kalkulator
</a></li>
...
...
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