diff --git a/cl-bscsd-22-48/.gitignore b/cl-bscsd-22-48/.gitignore new file mode 100644 index 0000000..8058e11 --- /dev/null +++ b/cl-bscsd-22-48/.gitignore @@ -0,0 +1 @@ +/project1/target/ diff --git a/cl-bscsd-22-48/my-webapp01/nb-configuration.xml b/cl-bscsd-22-48/my-webapp01/nb-configuration.xml new file mode 100644 index 0000000..cab3429 --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/nb-configuration.xml @@ -0,0 +1,22 @@ + + + + + + 1.7-web + Tomcat + + + href + + diff --git a/cl-bscsd-22-48/my-webapp01/pom.xml b/cl-bscsd-22-48/my-webapp01/pom.xml new file mode 100644 index 0000000..0f550be --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + + com.mycompany + my-webapp01 + 1.0-SNAPSHOT + war + + my-webapp01 + + + ${project.build.directory}/endorsed + UTF-8 + + + + + javax + javaee-web-api + 7.0 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + ${endorsed.dir} + + + + + org.apache.maven.plugins + maven-war-plugin + 2.3 + + false + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.6 + + + validate + + copy + + + ${endorsed.dir} + true + + + javax + javaee-endorsed-api + 7.0 + jar + + + + + + + + + + diff --git a/cl-bscsd-22-48/my-webapp01/src/main/java/oop/Person.java b/cl-bscsd-22-48/my-webapp01/src/main/java/oop/Person.java new file mode 100644 index 0000000..2db2682 --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/src/main/java/oop/Person.java @@ -0,0 +1,81 @@ +package oop; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author UNKNOWN_BRO + */ +public class Person { + private String nic; + private String name; + private String dob; + private String gender; + private String id; + + public Person() { + this.nic = ""; + this.name = ""; + this.dob = ""; + this.gender = ""; + + } + + public Person(String nic, String name , String dob , String gender) { + this.nic = nic; + this.name = name; + this.dob = dob; + this.gender = gender; + + + } + + Person(String v, String john) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + + public String getNic() { + return nic; + } + + public void setNic(String nic) { + this.nic = nic; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDOB() { + return dob; + } + + public void setDOB(String dob) { + this.dob = dob; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + + public void test() { + System.out.println("test"); + } + + + +} diff --git a/cl-bscsd-22-48/my-webapp01/src/main/java/oop/UserSession.java b/cl-bscsd-22-48/my-webapp01/src/main/java/oop/UserSession.java new file mode 100644 index 0000000..af79f2a --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/src/main/java/oop/UserSession.java @@ -0,0 +1,77 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package oop; + +/** + * + * @author UNKNOWN_BRO + */ +public class UserSession { + + private String userName; + private String firstName; + private String lastName; + private String remarks; + private String id; + + + public UserSession() { + } + + public UserSession(String userName, String firstName, String lastName, String remarks , String id) { + this.userName = userName; + this.firstName = firstName; + this.lastName = lastName; + this.remarks = remarks; + this.id = id; + } + + + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getRemarks() { + return remarks; + } + + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + + + +} diff --git a/cl-bscsd-22-48/my-webapp01/src/main/java/oop/Utils.java b/cl-bscsd-22-48/my-webapp01/src/main/java/oop/Utils.java new file mode 100644 index 0000000..f98d55e --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/src/main/java/oop/Utils.java @@ -0,0 +1,97 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package oop; + + +import java.io.IOException; +import java.util.List; +import java.util.ArrayList; +import java.util.UUID; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +/** + * + * @author UNKNOWN_BRO + */ +public class Utils { + + + public static List getPersons(){ + + List persons = new ArrayList<>(); + + persons.add(new Person("123v" , "john" , "12/10/2021" , "male" )); + persons.add(new Person("123v" , "philip" , "16/11/2010" , "female")); + persons.add(new Person("123v" , "nike" , "17/10/2014" , "male")); + persons.add(new Person("123v" , "jorge" , "11/09/2014" , "male")); + + return persons; + + } + + public static String getPersonsHTML(){ + String output = ""; + output += "" + +"" + +"" + +"" + +""; + + for (Person p : Utils.getPersons()){ + output += ""; + output += ""; + output += ""; + output += ""; + output += ""; + output += ""; + } + output += "
NICNAMEDOBGender
" + p.getNic() + "" + p.getName() + "" + p.getDOB() + "" + p.getGender() + "
"; + return output; + } + + public static UserSession authinticate(String uname , String pwd){ + UserSession usersession = null; + if(uname!= null && pwd != null & + uname.equals("ranula") && pwd.equals("123")){ + String sesid = UUID.randomUUID().toString().replace("-","").toUpperCase(); + usersession = new UserSession( "ranula" , "ranula" , "suwin" , "none", sesid ); + + } + + return usersession; + } + + public static UserSession handleusersession(HttpServletRequest request,HttpServletResponse response, HttpSession session){ + String uname = request.getParameter("uname"); + String pwd = request.getParameter("pwd"); + + UserSession usersession = Utils.authinticate(uname, pwd); + + if(usersession == null ){ + for(Cookie cookie : request.getCookies()){ + if (cookie.getName().equals("sesid")){ + usersession = (UserSession) session.getAttribute(cookie.getValue()); + + } + } + + }else{ + + session.setAttribute(usersession.getId(), usersession); + Cookie cookie = new Cookie("sesid" , usersession.getId() ); + response.addCookie(cookie); + + } + return usersession; + } + + + } + + diff --git a/cl-bscsd-22-48/my-webapp01/src/main/webapp/META-INF/context.xml b/cl-bscsd-22-48/my-webapp01/src/main/webapp/META-INF/context.xml new file mode 100644 index 0000000..dab07ad --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/src/main/webapp/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/cl-bscsd-22-48/my-webapp01/src/main/webapp/handle-logout.jsp b/cl-bscsd-22-48/my-webapp01/src/main/webapp/handle-logout.jsp new file mode 100644 index 0000000..82e899e --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/src/main/webapp/handle-logout.jsp @@ -0,0 +1,12 @@ +<%@page import="oop.Utils"%> +<%@page import="oop.UserSession"%> +<% + UserSession usersession = Utils.handleusersession(request, response, session); + if (usersession != null){ + //session.removeAttribute(session.getId()); + session.invalidate(); + } + response.sendRedirect("login.jsp"); + + +%> diff --git a/cl-bscsd-22-48/my-webapp01/src/main/webapp/index.jsp b/cl-bscsd-22-48/my-webapp01/src/main/webapp/index.jsp new file mode 100644 index 0000000..df8f268 --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/src/main/webapp/index.jsp @@ -0,0 +1,41 @@ +<%-- + Document : index + Created on : Aug 27, 2021, 9:08:18 PM + Author : UNKNOWN_BRO +--%> + +<%@page import="oop.UserSession"%> +<%@page import="java.util.UUID"%> +<%@page import="oop.Utils"%> +<%@page import="java.util.List"%> +<%@page import="oop.Person"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + JSP Page + + +
+ +
+ + <% + UserSession usersession = Utils.handleusersession(request, response, session); + if (usersession == null){ + response.sendRedirect("login.jsp"); + }else{ + + + %> +

Welcome <%out.print(usersession.getUserName()); %> + <% + out.print(Utils.getPersonsHTML() ); + %> + <%}%> + + + + + diff --git a/cl-bscsd-22-48/my-webapp01/src/main/webapp/login.jsp b/cl-bscsd-22-48/my-webapp01/src/main/webapp/login.jsp new file mode 100644 index 0000000..dc4c4c0 --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/src/main/webapp/login.jsp @@ -0,0 +1,24 @@ +<%-- + Document : login + Created on : Aug 31, 2021, 7:30:51 PM + Author : UNKNOWN_BRO +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + JSP Page + +
+
+
+
+

+ +
+ + + + diff --git a/cl-bscsd-22-48/my-webapp01/src/main/webapp/profile.jsp b/cl-bscsd-22-48/my-webapp01/src/main/webapp/profile.jsp new file mode 100644 index 0000000..5807ab6 --- /dev/null +++ b/cl-bscsd-22-48/my-webapp01/src/main/webapp/profile.jsp @@ -0,0 +1,36 @@ + <%@page import="oop.Utils"%> +<%@page import="oop.UserSession"%> +<%-- + Document : profile + Created on : Sep 2, 2021, 11:13:04 AM + Author : UNKNOWN_BRO +--%> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + JSP Page + + + + + + + <%UserSession usersession = Utils.handleusersession(request, response, session); + if (usersession == null){ + response.sendRedirect("login.jsp"); + } + %> +

Hello World!

+ + diff --git a/cl-bscsd-22-48/project1/pom.xml b/cl-bscsd-22-48/project1/pom.xml new file mode 100644 index 0000000..58c2a29 --- /dev/null +++ b/cl-bscsd-22-48/project1/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + com.mycompany + project1 + 1.0-SNAPSHOT + jar + + UTF-8 + 11 + 11 + + \ No newline at end of file diff --git a/cl-bscsd-22-48/project1/src/main/java/run.java b/cl-bscsd-22-48/project1/src/main/java/run.java new file mode 100644 index 0000000..3ae7385 --- /dev/null +++ b/cl-bscsd-22-48/project1/src/main/java/run.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author UNKNOWN_BRO + */ +public class run { + + public static void main(String[] args){ + + + for (int a = 0; a <4; a++){ + System.out.println("****"); + } + + + + + + } + } + + diff --git a/cl-bscsd-22-48/readme.md b/cl-bscsd-22-48/readme.md new file mode 100644 index 0000000..4438cc7 --- /dev/null +++ b/cl-bscsd-22-48/readme.md @@ -0,0 +1,2 @@ +ranula +suwin