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
d591e877
Commit
d591e877
authored
Sep 29, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wprowadzenie do beanów
parent
0986a1e8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
11 deletions
+21
-11
InfoBean.java
PC25-Serwlety/src/main/java/beans/InfoBean.java
+18
-8
przyklad.jsp
PC25-Serwlety/src/main/webapp/przyklad.jsp
+3
-3
No files found.
PC25-Serwlety/src/main/java/beans/InfoBean.java
View file @
d591e877
package
beans
;
import
java.time.LocalTime
;
import
java.time.Local
Date
Time
;
public
class
InfoBean
{
/* Klasa jest "Java Bean" jeśli:
...
...
@@ -11,15 +11,19 @@ public class InfoBean {
// konstruktor domyślny jest tworzony automatycznie
private
String
napis
=
"Początkowy napis"
;
private
String
tekst
=
"Początkowy napis"
;
private
int
licznik
=
0
;
public
String
get
Napis
()
{
return
napis
;
public
String
get
Tekst
()
{
return
tekst
;
}
public
void
setNapis
(
String
napis
)
{
this
.
napis
=
napis
;
public
String
getTekstDuze
()
{
return
tekst
.
toUpperCase
();
}
public
void
setTekst
(
String
napis
)
{
this
.
tekst
=
napis
;
}
public
int
getLicznik
()
{
...
...
@@ -30,8 +34,8 @@ public class InfoBean {
this
.
licznik
=
licznik
;
}
public
LocalTime
getCurrentTime
()
{
return
LocalTime
.
now
();
public
Local
Date
Time
getCurrentTime
()
{
return
Local
Date
Time
.
now
();
}
// eksperyment: jeśli są dwie metody, to wybiera mała literę
...
...
@@ -39,5 +43,11 @@ public class InfoBean {
// return "mała litera";
// }
@Override
public
String
toString
()
{
return
"InfoBean["
+
tekst
+
"]"
;
}
}
PC25-Serwlety/src/main/webapp/przyklad.jsp
View file @
d591e877
...
...
@@ -71,18 +71,18 @@ oraz biblioteki tagów (taglibs) w połaczeniu z dostępem do obiektów "bean" p
<p>
pola obiektu ala: ${ala.imie}, ${ala.nazwisko}, opis: ${ala.opis}
</p>
<jsp:useBean
id=
"obiekt"
class=
"beans.InfoBean"
/>
<jsp:useBean
id=
"obiekt"
class=
"beans.InfoBean"
scope=
"session"
/>
<p>
Mam beana: ${obiekt}
</p>
<p>
Tekst: ${obiekt.tekst}
</p>
<
%
--
Tak
naprawd
ę
wywo
ł
ywane
jest
obiekt
.
getTekst
()
--
%
>
<
%
--
A
teraz
obiekt
.
setTekst
("
Ola
ma
psa
nr
5
")
--
%
>
<jsp:setProperty
name=
"obiekt"
property=
"tekst"
value=
"Ola ma psa nr ${
2+3
}"
/>
<jsp:setProperty
name=
"obiekt"
property=
"tekst"
value=
"Ola ma psa nr ${
10 + obiekt.licznik
}"
/>
<p>
Tekst po zmianie: ${obiekt.tekst}
</p>
<p>
upper: ${obiekt.tekstDuze}
</p>
<p>
czas: ${obiekt.currentTime}
</p>
<p>
pola daty i czasu: ${obiekt.currentTime.hour}:${obiekt.currentTime.minute} , dzień roku: ${obiekt.currentTime.dayOfYear}
</p>
<p>
licznik: ${obiekt.licznik}
</p>
</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