Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
latihanJavaServlet_Dwinowo_Muhammad
Project
Project
Details
Activity
Releases
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
Dwinowo Muhammad
latihanJavaServlet_Dwinowo_Muhammad
Commits
3d363f6c
Commit
3d363f6c
authored
Mar 22, 2022
by
Dwinowo Muhammad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Penambahan login session pada Latihan3.java + DashboardProfile
parent
5b417ba4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
10 deletions
+87
-10
DashboardProfile.java
src/main/java/com/belajarServlet/web/DashboardProfile.java
+60
-0
Latihan3.java
src/main/java/com/belajarServlet/web/Latihan3.java
+14
-9
DashboardProfile.jsp
src/main/webapp/DashboardProfile.jsp
+12
-0
Latihan3.jsp
src/main/webapp/Latihan3.jsp
+1
-1
No files found.
src/main/java/com/belajarServlet/web/DashboardProfile.java
0 → 100644
View file @
3d363f6c
package
com
.
belajarServlet
.
web
;
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
;
import
javax.servlet.http.HttpSession
;
/**
* Servlet implementation class DashboardProfile
*/
@WebServlet
(
"/DashboardProfile"
)
public
class
DashboardProfile
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* @see HttpServlet#HttpServlet()
*/
public
DashboardProfile
()
{
super
();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
PrintWriter
out
=
response
.
getWriter
();
HttpSession
session
=
request
.
getSession
(
true
);
String
username
=
(
String
)
session
.
getValue
(
"username"
);
// get response writer
PrintWriter
writer
=
response
.
getWriter
();
// build html code
String
htmlResponse
=
"<html>"
;
htmlResponse
+=
"<h2> Selamat Datang "
+
username
+
"<br/>"
;
//return response
writer
.
println
(
htmlResponse
);
// response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
// TODO Auto-generated method stub
doGet
(
request
,
response
);
}
}
src/main/java/com/belajarServlet/web/Latihan3.java
View file @
3d363f6c
...
...
@@ -8,6 +8,7 @@ import javax.servlet.annotation.WebServlet;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
/**
* Servlet implementation class Latihan3
...
...
@@ -30,6 +31,15 @@ public class Latihan3 extends HttpServlet {
*/
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
PrintWriter
out
=
response
.
getWriter
();
String
userName
=
request
.
getParameter
(
"username"
).
toString
();
String
password
=
request
.
getParameter
(
"password"
).
toString
();
...
...
@@ -43,6 +53,10 @@ public class Latihan3 extends HttpServlet {
if
(
password
.
equals
(
passwordAgus
)
&&
userName
.
equals
(
userAgus
))
{
out
.
println
(
"<h1> Login Sukses </h1>"
);
out
.
println
(
"<p> Selamat Datang </p> "
+
userName
);
HttpSession
session
=
request
.
getSession
(
true
);
session
.
putValue
(
"username"
,
userName
);
response
.
sendRedirect
(
request
.
getContextPath
()+
"/DashboardProfile"
);
}
else
if
(!
password
.
equals
(
passwordAgus
)
&&
!
userName
.
equals
(
userAgus
))
{
out
.
println
(
"<h1> Login Gagal </h1>"
);
out
.
println
(
"<p> Username dan password anda salah!!! </p>"
);
...
...
@@ -59,15 +73,6 @@ public class Latihan3 extends HttpServlet {
out
.
println
(
"</body>"
);
out
.
println
(
"</html>"
);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
// TODO Auto-generated method stub
doGet
(
request
,
response
);
}
...
...
src/main/webapp/DashboardProfile.jsp
0 → 100644
View file @
3d363f6c
<%@ page
language=
"java"
contentType=
"text/html; charset=ISO-8859-1"
pageEncoding=
"ISO-8859-1"
%>
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"ISO-8859-1"
>
<title>
Selamat Datang
</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
src/main/webapp/Latihan3.jsp
View file @
3d363f6c
...
...
@@ -7,7 +7,7 @@
<title>
Latihan3
</title>
</head>
<body>
<form
action=
"Latihan3"
>
<form
action=
"Latihan3"
method=
"post"
>
<label
for=
"fname"
>
Username:
</label><br>
<input
type=
"text"
id=
"username"
name=
"username"
><br>
<label
for=
"lname"
>
Password:
</label><br>
...
...
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