Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
EJB-Calculator
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web2
EJB-Calculator
Commits
77958981
Commit
77958981
authored
9 years ago
by
Carlos Eduardo da Silva
Browse files
Options
Downloads
Patches
Plain Diff
The Servlet.
parent
18339191
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Calculator-Web/JavaSource/br/ufrn/imd/imd0409/calculator/servlet/CalculatorServlet.java
+74
-0
74 additions, 0 deletions
...frn/imd/imd0409/calculator/servlet/CalculatorServlet.java
Calculator-Web/WebContent/formulario.html
+15
-0
15 additions, 0 deletions
Calculator-Web/WebContent/formulario.html
with
89 additions
and
0 deletions
Calculator-Web/JavaSource/br/ufrn/imd/imd0409/calculator/servlet/CalculatorServlet.java
0 → 100644
+
74
−
0
View file @
77958981
package
br.ufrn.imd.imd0409.calculator.servlet
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
javax.ejb.EJB
;
import
javax.servlet.ServletException
;
import
javax.servlet.annotation.WebServlet
;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
br.ufrn.imd.imd0409.calculator.bean.NoInterfaceViewCalculatorBean
;
/**
* Servlet implementation class CalculatorServlet
*/
@WebServlet
(
"/CalculatorServlet"
)
public
class
CalculatorServlet
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
@EJB
private
NoInterfaceViewCalculatorBean
calc
;
/**
* @see HttpServlet#HttpServlet()
*/
public
CalculatorServlet
()
{
super
();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
processRequest
(
request
,
response
);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
processRequest
(
request
,
response
);
}
protected
void
processRequest
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
response
.
setContentType
(
"text/html;charset=UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
"<html>"
);
out
.
println
(
"<head>"
);
out
.
println
(
"<title>Resulado com Servlet</title>"
);
out
.
println
(
"</head>"
);
out
.
println
(
"<body>"
);
try
{
int
numero1
=
Integer
.
parseInt
(
request
.
getParameter
(
"numero1"
));
int
numero2
=
Integer
.
parseInt
(
request
.
getParameter
(
"numero2"
));
out
.
println
(
"Numero 1: "
+
numero1
+
"<br>"
);
out
.
println
(
"Numero 2: "
+
numero2
+
"<br>"
);
out
.
println
(
"Resultado: "
+
calc
.
add
(
numero1
,
numero2
)
+
"<br>"
);
}
catch
(
Exception
e
)
{
out
.
println
(
"ERROR: "
+
e
.
getLocalizedMessage
()
+
"<br>"
);
e
.
printStackTrace
(
out
);
}
finally
{
out
.
println
(
"</body></html>"
);
out
.
close
();
}
}
}
This diff is collapsed.
Click to expand it.
Calculator-Web/WebContent/formulario.html
0 → 100644
+
15
−
0
View file @
77958981
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Example with Calculator Servlet
</title>
</head>
<body>
Chamando o bean de um Servlet
<br>
<form
action=
"CalculatorServlet"
method=
"get"
>
Numero1:
<input
type=
"text"
name=
"numero1"
>
<br>
Numero2:
<input
type=
"text"
name=
"numero2"
>
<br>
<input
type=
"submit"
>
</form>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment