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
139f0d36
Commit
139f0d36
authored
Sep 28, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Przykład Info i aktualizacja spisu treści
parent
4506f643
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
3 deletions
+91
-3
Info.java
PC25-Serwlety/src/main/java/techniczne/Info.java
+84
-0
index.html
PC25-Serwlety/src/main/webapp/index.html
+7
-3
No files found.
PC25-Serwlety/src/main/java/techniczne/Info.java
0 → 100644
View file @
139f0d36
package
techniczne
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.time.LocalTime
;
import
java.util.Arrays
;
import
java.util.Enumeration
;
import
java.util.Map
;
import
javax.servlet.ServletException
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
// Można spróbować z takimi parametrami:
// http://localhost:8080/PC24-Serwlety/Info?x=Ala&y=Ola&x=Ela&x=Ula&z=Asia
@WebServlet
(
"/Info"
)
// mogłby być też wpis w web.xml
public
class
Info
extends
HttpServlet
{
@Override
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
String
teraz
=
LocalTime
.
now
().
toString
();
response
.
setContentType
(
"text/plain"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
addCookie
(
new
Cookie
(
"czas"
,
teraz
));
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
"Halo halo"
);
out
.
println
(
"ContextPath: "
+
request
.
getContextPath
());
out
.
println
(
"RequestURI: "
+
request
.
getRequestURI
());
out
.
println
(
"QueryString: "
+
request
.
getQueryString
());
out
.
println
();
out
.
println
(
"LocalName: "
+
request
.
getLocalName
());
out
.
println
(
"LocalAddr: "
+
request
.
getLocalAddr
());
out
.
println
(
"LocalPort: "
+
request
.
getLocalPort
());
out
.
println
();
out
.
println
(
"RemoteHost: "
+
request
.
getRemoteHost
());
out
.
println
(
"RemoteAddr: "
+
request
.
getRemoteAddr
());
// itd.
out
.
println
();
out
.
println
(
"parametr x: "
+
request
.
getParameter
(
"x"
));
out
.
println
(
"parametr y: "
+
request
.
getParameter
(
"y"
));
String
[]
wartosciX
=
request
.
getParameterValues
(
"x"
);
out
.
println
(
"x jako tablica: "
+
Arrays
.
toString
(
wartosciX
));
out
.
println
(
"Wszystkie parametry:"
);
for
(
Map
.
Entry
e
:
request
.
getParameterMap
().
entrySet
())
{
String
[]
v
=
(
String
[])
e
.
getValue
();
out
.
println
(
" * "
+
e
.
getKey
()
+
" : "
+
Arrays
.
toString
(
v
));
}
out
.
println
();
out
.
println
(
"nagłówek Accept: "
+
request
.
getHeader
(
"Accept"
));
out
.
println
(
"nagłówek User-Agent: "
+
request
.
getHeader
(
"User-Agent"
));
out
.
println
(
"Wszystkie nagłówki:"
);
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
while
(
headerNames
.
hasMoreElements
())
{
String
nm
=
headerNames
.
nextElement
();
out
.
println
(
nm
+
": "
+
request
.
getHeader
(
nm
));
}
out
.
println
();
out
.
println
(
"Wszystkie ciastka:"
);
String
poprzedniCzas
=
null
;
Cookie
[]
cookies
=
request
.
getCookies
();
if
(
cookies
!=
null
)
for
(
Cookie
cooky
:
cookies
)
{
out
.
println
(
"cookie "
+
cooky
.
getName
()
+
" "
+
cooky
.
getValue
());
if
(
"czas"
.
equals
(
cooky
.
getName
()))
{
poprzedniCzas
=
cooky
.
getValue
();
}
}
out
.
println
(
"czas teraz : "
+
teraz
);
out
.
println
(
"czas poprzedni: "
+
poprzedniCzas
);
}
}
PC25-Serwlety/src/main/webapp/index.html
View file @
139f0d36
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
<li><a
href=
"stronka.html"
>
zwykła strona HTML
</a></li>
<li><a
href=
"stronka.html"
>
zwykła strona HTML
</a></li>
<li><a
href=
"Hello"
>
serwlet Hello
</a></li>
<li><a
href=
"Hello"
>
serwlet Hello
</a></li>
<li><a
href=
"Ping"
>
Ping
</a></li>
<li><a
href=
"Ping"
>
Ping
</a></li>
<li><a
href=
"Info"
>
Info
</a>
- informacje techniczne o zapytaniu
</li>
</ul>
</ul>
<h3>
Pierwsze parametry
</h3>
<h3>
Pierwsze parametry
</h3>
...
@@ -22,12 +23,15 @@
...
@@ -22,12 +23,15 @@
<li><a
href=
"Parametry?imie=Ala"
>
Parametry?imie=Ala
</a>
- tylko imię
</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=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>
<li><a
href=
"Parametry?imie=Ala&wiek=14"
>
Parametry?imie=Ala
&
wiek=14
</a>
- niepełnoletnia
</li>
<li><a
href=
"Formularz"
>
Formularz
</a>
- prosta rozmowa
</li>
</ul>
</ul>
<h3>
Formularze w serwletach
</h3>
<h3>
Kalkulator
</h3>
<ul>
<ul>
<li><a
href=
"Formularz"
>
Formularz
</a>
- prosta rozmowa
</li>
<li><a
href=
"Kalulator1"
>
Kalkulator1
</a>
- tylko dodawanie
</li>
<li><a
href=
"Kalulator2"
>
Kalkulator2
</a>
- wiele działań, GET
</li>
<li><a
href=
"Kalulator3"
>
Kalkulator3
</a>
- formularz typu POST
</li>
<li><a
href=
"Kalulator4"
>
Kalkulator4
</a>
- zrefaktoryzowany POST
</li>
</ul>
</ul>
</body>
</body>
...
...
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