Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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_20230617
Commits
2acb7042
Commit
2acb7042
authored
Jul 01, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kalkulator - tylko dodawanie
parent
e7267f61
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
Kalkulator.java
...-Servlety/src/main/java/serwlety/podstawy/Kalkulator.java
+53
-0
No files found.
PC23-Servlety/src/main/java/serwlety/podstawy/Kalkulator.java
0 → 100644
View file @
2acb7042
package
serwlety
.
podstawy
;
import
jakarta.servlet.ServletException
;
import
jakarta.servlet.annotation.WebServlet
;
import
jakarta.servlet.http.HttpServlet
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
@WebServlet
(
"/kalkulator"
)
public
class
Kalkulator
extends
HttpServlet
{
@Override
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
final
String
poczatek
=
"""
<!DOCTYPE html>
<html>
<head>
<title>Rozmowa serlwetowa</title>
</head>
<body>"""
;
final
String
formularz
=
"""
<form>
<label for="
liczba1
">Pierwsza liczba:</label>
<input name="
liczba1
">
<br/>
<label for="
liczba2
">Druga liczba:</label>
<input name="
liczba2
">
<br/>
<button>Wyślij</button>
</form>"""
;
final
String
koniec
=
"""
</body>
</html>"""
;
response
.
setContentType
(
"text/html"
);
// MIME type / Content-Type
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
poczatek
);
out
.
println
(
formularz
);
try
{
int
liczba1
=
Integer
.
parseInt
(
request
.
getParameter
(
"liczba1"
));
int
liczba2
=
Integer
.
parseInt
(
request
.
getParameter
(
"liczba2"
));
out
.
println
(
"<div>Suma "
+
(
liczba1
+
liczba2
)
+
"</div>"
);
}
catch
(
NumberFormatException
e
)
{
out
.
println
(
"Niepoprawny format liczby"
);
}
out
.
println
(
koniec
);
}
}
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