Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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_dzienna_15_09
Commits
3f317e78
Commit
3f317e78
authored
Sep 28, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pierwsze parametry
parent
c0e35730
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
2 deletions
+88
-2
Ping.java
PC25-Serwlety/src/main/java/hello/Ping.java
+35
-0
Parametry.java
PC25-Serwlety/src/main/java/parametry/Parametry.java
+42
-0
index.html
PC25-Serwlety/src/main/webapp/index.html
+11
-2
No files found.
PC25-Serwlety/src/main/java/hello/Ping.java
0 → 100644
View file @
3f317e78
package
hello
;
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
(
"/Ping"
)
public
class
Ping
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
LocalDateTime
dt
=
LocalDateTime
.
now
();
String
addr
=
request
.
getRemoteAddr
();
System
.
out
.
println
(
dt
+
", zapytanie z adresu "
+
addr
);
response
.
setContentType
(
"text/html"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
"<html><head>"
);
out
.
println
(
"<link rel='stylesheet' type='text/css' href='styl.css'>"
);
out
.
println
(
"</head>"
);
out
.
println
(
"<body>"
);
out
.
println
(
"<p>Twój adres: <strong>"
+
addr
+
"</strong></p>"
);
out
.
println
(
"<p>Bieżący czas: <strong>"
+
dt
+
"</strong></p>"
);
out
.
println
(
"</body></html>"
);
}
}
PC25-Serwlety/src/main/java/parametry/Parametry.java
0 → 100644
View file @
3f317e78
package
parametry
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
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
(
"/Parametry"
)
public
class
Parametry
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
response
.
setContentType
(
"text/plain"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
// W zapytaniu mogą zostać przysłane "parametry".
// W przypadku zapytania typu GET, parametry są zakodowane na końcu ścieżki URL
// .../adres?parametr1=wartość¶metr2=wartość
// w przypadku zapytań POST, parametry są przysłane w treści zapytania.
// W obu sytuacjach wartość parametru można odczytać za pomocą request.getParameter("NAZWA")
String
imie
=
request
.
getParameter
(
"imie"
);
out
.
println
(
"Witaj "
+
imie
+
"!"
);
String
wiekTekstowo
=
request
.
getParameter
(
"wiek"
);
if
(
wiekTekstowo
!=
null
)
{
int
wiek
=
Integer
.
parseInt
(
wiekTekstowo
);
if
(
wiek
>=
18
)
{
out
.
println
(
"Chodź na piwo"
);
}
else
{
out
.
println
(
"Może czekoladę?"
);
}
}
}
}
PC25-Serwlety/src/main/webapp/index.html
View file @
3f317e78
...
...
@@ -9,10 +9,20 @@
<body>
<h1>
Aplikacja serwletowa
—
spis treści
</h1>
<h3>
Podstawy
</h3>
<ul>
<li><a
href=
"stronka.html"
>
zwykła strona HTML
</a></li>
<li><a
href=
"Hello"
>
serwlet Hello
</a></li>
<li><a
href=
"Ping"
>
Ping
</a></li>
</ul>
<h3>
Pierwsze parametry
</h3>
<ul>
<li><a
href=
"Parametry"
>
Parametry
</a>
- bez parametrów
</li>
<li><a
href=
"Parametry?imie=Ala"
>
Parametry?imie=Ala
</a>
- tylko imię
</li>
<li><a
href=
"Parametry?imie=Ala&wiek=30"
>
Parametry?imie=Ala
&
wiek=30
</a>
- pełnoletnia
</li>
<li><a
href=
"Parametry?imie=Ala&wiek=14"
>
Parametry?imie=Ala
&
wiek=14
</a>
- niepełnoletnia
</li>
</ul>
</body>
</html>
\ No newline at end of file
</html>
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