Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web app #76

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cl-bscsd-22-48/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/project1/target/
22 changes: 22 additions & 0 deletions cl-bscsd-22-48/my-webapp01/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
</properties>
<spellchecker-wordlist xmlns="http://www.netbeans.org/ns/spellchecker-wordlist/1">
<word>href</word>
</spellchecker-wordlist>
</project-shared-configuration>
76 changes: 76 additions & 0 deletions cl-bscsd-22-48/my-webapp01/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>my-webapp01</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>my-webapp01</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
81 changes: 81 additions & 0 deletions cl-bscsd-22-48/my-webapp01/src/main/java/oop/Person.java
Original file line number Diff line number Diff line change
@@ -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");
}



}
77 changes: 77 additions & 0 deletions cl-bscsd-22-48/my-webapp01/src/main/java/oop/UserSession.java
Original file line number Diff line number Diff line change
@@ -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;
}




}
97 changes: 97 additions & 0 deletions cl-bscsd-22-48/my-webapp01/src/main/java/oop/Utils.java
Original file line number Diff line number Diff line change
@@ -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<Person> getPersons(){

List<Person> 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 = "<table border='#0099ff' , border-collapse: 'collapse' , width: '8px'>";
output += "<tr><th>NIC</th>"
+"<th>NAME</th>"
+"<th>DOB</th>"
+"<th>Gender</th>"
+"</tr>";

for (Person p : Utils.getPersons()){
output += "<tr>";
output += "<td>" + p.getNic() + "</td>";
output += "<td>" + p.getName() + "</td>";
output += "<td>" + p.getDOB() + "</td>";
output += "<td>" + p.getGender() + "</td>";
output += "</tr>";
}
output += "</table>";
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;
}


}


Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/my-webapp01"/>
12 changes: 12 additions & 0 deletions cl-bscsd-22-48/my-webapp01/src/main/webapp/handle-logout.jsp
Original file line number Diff line number Diff line change
@@ -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");


%>
Loading