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
670ad644
Commit
670ad644
authored
Oct 19, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parametry techniczne
parent
c5038f82
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
ParametryController.java
...g/src/main/java/com/example/demo/ParametryController.java
+21
-0
index.html
PC26-Spring/src/main/resources/templates/index.html
+1
-0
No files found.
PC26-Spring/src/main/java/com/example/demo/ParametryController.java
View file @
670ad644
...
...
@@ -2,10 +2,13 @@ package com.example.demo;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestHeader
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
jakarta.servlet.http.HttpServletRequest
;
@Controller
@RequestMapping
(
"/parametry"
)
public
class
ParametryController
{
...
...
@@ -37,4 +40,22 @@ public class ParametryController {
// Parametry z adnotacją @RequestParam są domyślnie obowiązkowe. Aby był opcjonalny,
// trzeba wpisać required=false (wtedy brak parametru = null)
// lub podać defaultValue.
// Wpisując do własnych metod parametry specjalnych typów, albo używając specjalnych adnotacji,
// możemy uzyskać dostęp do różnych klas narzędziowych serwera lub informacji związanych z zapytaniem.
@GetMapping
(
path
=
"/techniczne"
,
produces
=
"text/plain;charset=UTF-8"
)
@ResponseBody
public
String
parametryTechniczne
(
HttpServletRequest
request
,
@RequestHeader
(
"User-Agent"
)
String
agent
)
{
return
"""
adres IP klienta: %s:%d
adres serwera: %s:%d
User-Agent z requestu: %s
User-Agent z parametru: %s
"""
.
formatted
(
request
.
getRemoteAddr
(),
request
.
getRemotePort
(),
request
.
getLocalAddr
(),
request
.
getLocalPort
(),
request
.
getHeader
(
"User-Agent"
),
agent
);
}
}
PC26-Spring/src/main/resources/templates/index.html
View file @
670ad644
...
...
@@ -32,6 +32,7 @@
<li><a
th:href=
"@{/parametry/powtorz}"
>
powtorz
</a></li>
<li><a
th:href=
"@{/parametry/powtorz(tekst='Ola ma psa')}"
>
powtorz
</a>
n = 1
</li>
<li><a
th:href=
"@{/parametry/powtorz(tekst='Ala ma kota',n=10)}"
>
powtorz
</a>
n = 10
</li>
<li><a
th:href=
"@{/parametry/techniczne}"
>
parametry techniczne
</a></li>
</ul>
<h2>
Formularze
</h2>
...
...
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