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
34b8f50a
Commit
34b8f50a
authored
Sep 28, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kalkulator1
parent
08989028
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
0 deletions
+93
-0
Kalkulator1.java
PC25-Serwlety/src/main/java/kalkulator/Kalkulator1.java
+56
-0
styl.css
PC25-Serwlety/src/main/webapp/styl.css
+27
-0
zadanie_kalkulator.txt
PC25-Serwlety/zadanie_kalkulator.txt
+10
-0
No files found.
PC25-Serwlety/src/main/java/kalkulator/Kalkulator1.java
0 → 100644
View file @
34b8f50a
package
kalkulator
;
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
(
"/Kalkulator1"
)
public
class
Kalkulator1
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
();
out
.
println
(
"<!DOCTYPE html>"
);
out
.
println
(
"<html>"
);
out
.
println
(
"<head>"
);
out
.
println
(
"<title>Kalkulator serwletowy</title>"
);
out
.
println
(
"<link rel='stylesheet' type='text/css' href='styl.css'>"
);
out
.
println
(
"</head>"
);
out
.
println
(
"<body>"
);
out
.
println
(
"<h1>Kalkulator 1</h1>"
);
out
.
println
(
"<form>"
);
out
.
println
(
"<label for='liczba1'>Liczba 1:</label>"
);
out
.
println
(
"<input name='liczba1' type='text'>"
);
out
.
println
(
"<br>"
);
out
.
println
(
"<label for='liczba2'>Liczba 2:</label>"
);
out
.
println
(
"<input name='liczba2' type='text'>"
);
out
.
println
(
"<br>"
);
out
.
println
(
"<button>Oblicz</button>"
);
out
.
println
(
"</form>"
);
String
param1
=
request
.
getParameter
(
"liczba1"
);
String
param2
=
request
.
getParameter
(
"liczba2"
);
if
(
param1
!=
null
&&
param2
!=
null
)
{
try
{
long
liczba1
=
Long
.
parseLong
(
param1
);
long
liczba2
=
Long
.
parseLong
(
param2
);
long
wynik
=
liczba1
+
liczba2
;
out
.
println
(
"<div class='wynik'>Suma: "
+
wynik
+
"</div>"
);
}
catch
(
NumberFormatException
e
)
{
out
.
println
(
"<div class='error'>Niepoprawny format liczby</div>"
);
}
}
out
.
println
(
"</body>"
);
out
.
println
(
"</html>"
);
}
}
PC25-Serwlety/src/main/webapp/styl.css
View file @
34b8f50a
...
...
@@ -7,3 +7,30 @@ h1 {
text-align
:
center
;
color
:
blue
;
}
form
{
width
:
600px
;
background-color
:
#AAEEFF
;
margin
:
2em
auto
;
padding
:
0.75em
;
border
:
4px
solid
blue
;
}
.wynik
{
width
:
600px
;
background-color
:
#CCFFDD
;
margin
:
2em
auto
;
padding
:
0.75em
;
border
:
4px
outset
green
;
}
.error
{
width
:
600px
;
background-color
:
white
;
color
:
red
;
margin
:
2em
auto
;
padding
:
0.75em
;
border
:
4px
double
red
;
}
PC25-Serwlety/zadanie_kalkulator.txt
0 → 100644
View file @
34b8f50a
Utwórz nowy serwlet Kalkulator obsługujący doGet
- ContentType text/html
- formularz, który pozwala wpisać dwie liczby i znak działania
→ (docelowo wybór działania zrobimy za pomocą <select><option>
ale na początku może być input)
- jeśli w parametrach zostaną przysłane liczby i działanie,
to wykonaj obliczenie i umieść na stronie wynik tego działnia
if(liczba1 != null && liczba2 != null)
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