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
08989028
Commit
08989028
authored
Sep 28, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Formularz z prostą rozmową
parent
3f317e78
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
0 deletions
+69
-0
Formularz.java
PC25-Serwlety/src/main/java/parametry/Formularz.java
+63
-0
index.html
PC25-Serwlety/src/main/webapp/index.html
+6
-0
No files found.
PC25-Serwlety/src/main/java/parametry/Formularz.java
0 → 100644
View file @
08989028
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
(
"/Formularz"
)
public
class
Formularz
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
response
.
setContentType
(
"text/html"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
// Normalnie parametry zapytań biorą się stąd, że uzytkwnicy wpisuję do pól "formularza".
out
.
println
(
"<!DOCTYPE html>"
);
out
.
println
(
"<html>"
);
out
.
println
(
"<head>"
);
out
.
println
(
"<title>Rozmowa serwletowa</title>"
);
out
.
println
(
"<link rel='stylesheet' type='text/css' href='styl.css'>"
);
out
.
println
(
"</head>"
);
out
.
println
(
"<body>"
);
out
.
println
(
"<h1>Rozmowa serwletowa</h1>"
);
out
.
println
(
"<form>"
);
out
.
println
(
"<div>"
);
out
.
println
(
"<label for='imie'>Jak masz na imię?</label>"
);
out
.
println
(
"<input name='imie' type='text'>"
);
out
.
println
(
"</div>"
);
out
.
println
(
"<div>"
);
out
.
println
(
"<label for='wiek'>Ile masz lat?</label>"
);
out
.
println
(
"<input name='wiek' type='number'>"
);
out
.
println
(
"</div>"
);
out
.
println
(
"<button>Wyślij</button>"
);
out
.
println
(
"</form>"
);
String
imie
=
request
.
getParameter
(
"imie"
);
if
(
imie
!=
null
)
{
out
.
println
(
"<div>"
);
out
.
println
(
"Witaj "
+
imie
+
"!"
);
String
wiekTekstowo
=
request
.
getParameter
(
"wiek"
);
if
(
wiekTekstowo
!=
null
)
{
int
wiek
=
Integer
.
parseInt
(
wiekTekstowo
);
if
(
wiek
>=
18
)
{
out
.
println
(
"<br>Chodź na piwo"
);
}
else
{
out
.
println
(
"<br>Może czekoladę?"
);
}
}
out
.
println
(
"</div>"
);
}
out
.
println
(
"</body>"
);
out
.
println
(
"</html>"
);
}
}
PC25-Serwlety/src/main/webapp/index.html
View file @
08989028
...
...
@@ -24,5 +24,11 @@
<li><a
href=
"Parametry?imie=Ala&wiek=14"
>
Parametry?imie=Ala
&
wiek=14
</a>
- niepełnoletnia
</li>
</ul>
<h3>
Formularze w serwletach
</h3>
<ul>
<li><a
href=
"Formularz"
>
Formularz
</a>
- prosta rozmowa
</li>
</ul>
</body>
</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