Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
servlets
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Oscar Enrique Gonzalez Escurra
servlets
Commits
d4b588da
Commit
d4b588da
authored
May 24, 2022
by
OscarGonzalez97
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ejemplo de requestDispatcher
parent
1dd26d2a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
0 deletions
+82
-0
src/main/java/com/roshka/bootcamp/RequestDispatcherServlet.java
+36
-0
src/main/java/com/roshka/bootcamp/RequestDispatcherServletSuccess.java
+24
-0
src/main/webapp/estilos/login.css
+5
-0
src/main/webapp/login.html
+17
-0
No files found.
src/main/java/com/roshka/bootcamp/RequestDispatcherServlet.java
0 → 100644
View file @
d4b588da
package
com
.
roshka
.
bootcamp
;
import
jakarta.servlet.RequestDispatcher
;
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
(
"/login"
)
public
class
RequestDispatcherServlet
extends
HttpServlet
{
@Override
public
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
PrintWriter
out
=
response
.
getWriter
();
String
username
=
request
.
getParameter
(
"username"
);
String
password
=
request
.
getParameter
(
"password"
);
if
(
username
.
equals
(
"bootcamp"
)
&&
password
.
equals
(
"bootcamp"
))
{
// forward
RequestDispatcher
dispatcher
=
request
.
getRequestDispatcher
(
"RequestDispatcherServletSuccess"
);
dispatcher
.
forward
(
request
,
response
);
}
else
{
//include
out
.
print
(
"Usuario invalido!"
);
RequestDispatcher
rd
=
request
.
getRequestDispatcher
(
"/login.html"
);
rd
.
include
(
request
,
response
);
}
}
}
src/main/java/com/roshka/bootcamp/RequestDispatcherServletSuccess.java
0 → 100644
View file @
d4b588da
package
com
.
roshka
.
bootcamp
;
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
(
"/dispatcher"
)
public
class
RequestDispatcherServletSuccess
extends
HttpServlet
{
public
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
response
.
setContentType
(
"text/html"
);
PrintWriter
out
=
response
.
getWriter
();
String
n
=
request
.
getParameter
(
"username"
);
out
.
print
(
"Welcome "
+
n
);
}
}
src/main/webapp/estilos/login.css
0 → 100644
View file @
d4b588da
body
{
background-color
:
powderblue
;
}
\ No newline at end of file
src/main/webapp/login.html
0 → 100644
View file @
d4b588da
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Login
</title>
<link
rel=
"stylesheet"
href=
"estilos/login.css"
></link>
</head>
<body>
<form
method=
"post"
action=
"login"
>
<label>
username:
</label>
<input
type=
"text"
name=
"username"
><br/>
<input
type=
"password"
name=
"password"
><br/>
<input
type=
"submit"
>
</form>
</body>
</html>
\ No newline at end of file
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