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
f712c0c3
Commit
f712c0c3
authored
Oct 09, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Przykład Rozmowa
parent
442e7394
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
1 deletions
+58
-1
KtoraGodzinaHtml.java
PC23-Serwlety/src/main/java/podstawy/KtoraGodzinaHtml.java
+1
-1
Rozmowa.java
PC23-Serwlety/src/main/java/podstawy/Rozmowa.java
+57
-0
No files found.
PC23-Serwlety/src/main/java/podstawy/KtoraGodzinaHtml.java
View file @
f712c0c3
...
@@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletResponse;
...
@@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletResponse;
@WebServlet
(
"/godzina"
)
@WebServlet
(
"/godzina"
)
public
class
KtoraGodzinaHtml
extends
HttpServlet
{
public
class
KtoraGodzinaHtml
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
@Override
@Override
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
LocalDateTime
dt
=
LocalDateTime
.
now
();
LocalDateTime
dt
=
LocalDateTime
.
now
();
...
...
PC23-Serwlety/src/main/java/podstawy/Rozmowa.java
0 → 100644
View file @
f712c0c3
package
podstawy
;
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
(
"/Rozmowa"
)
public
class
Rozmowa
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
// Odczyt parametrów celowo umieszczam na początku metody, aby pokazać, że po wypełnieniu formularza
// i naciśnięciu Wyślij metoda do Get wykona się ponownie od początku
String
imie
=
request
.
getParameter
(
"imie"
);
String
parametrWiek
=
request
.
getParameter
(
"wiek"
);
System
.
out
.
println
(
"rozmowa wywołana z parametrem "
+
imie
);
response
.
setContentType
(
"text/html"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
"<!DOCTYPE html>"
);
out
.
println
(
"<html><head>"
);
out
.
println
(
"<title>Rozmowa serwletowa</title>"
);
out
.
println
(
"</head>"
);
out
.
println
(
"<body>"
);
out
.
println
(
"<h1>Rozmowa serwletowa</h1>"
);
out
.
println
(
"<form>"
);
out
.
println
(
"<label for='imie'>Jak masz na imię?</label>"
);
out
.
println
(
"<input type='text' name='imie'>"
);
out
.
println
(
"<label for='wiek'>Ile masz lat?</label>"
);
out
.
println
(
"<input type='number' name='wiek'>"
);
out
.
println
(
"<button>Wyślij</button>"
);
out
.
println
(
"</form>"
);
if
(
imie
!=
null
&&
!
imie
.
isEmpty
())
{
out
.
println
(
"<p>Witaj "
+
imie
+
"</p>"
);
if
(
parametrWiek
!=
null
&&
!
parametrWiek
.
isEmpty
())
{
int
wiek
=
Integer
.
parseInt
(
parametrWiek
);
if
(
wiek
>=
18
)
{
out
.
println
(
"<p>Zapraszamy na piwo.</p>"
);
}
else
{
out
.
println
(
"<p>Osoba niepełnoletnia.</p>"
);
}
}
}
out
.
println
(
"</body>"
);
out
.
println
(
"</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