Wednesday, April 20, 2016

Scrum Project SQL Script

CREATE TABLE PROJECT 
(
  PRJID NUMBER NOT NULL 
, PRJNAME VARCHAR2(20) NOT NULL 
, ESCALATION1 VARCHAR2(20) 
, ESCALATION2 VARCHAR2(20) 
, ESCALATION3 VARCHAR2(20) 
, SERVICEOWNERNAME VARCHAR2(20) NOT NULL 
, COUNTRY VARCHAR2(20) NOT NULL 
, CONSTRAINT PROJECT_PK PRIMARY KEY 
  (
    PRJID 
  )
  ENABLE 
);

COMMENT ON COLUMN PROJECT.PRJID IS 'Project ID for Projects';

COMMENT ON COLUMN PROJECT.PRJNAME IS 'Project Name';

COMMENT ON COLUMN PROJECT.ESCALATION1 IS 'Escalation 1';

COMMENT ON COLUMN PROJECT.ESCALATION2 IS 'Escalation 2';

COMMENT ON COLUMN PROJECT.ESCALATION3 IS 'Escalation 3';

COMMENT ON COLUMN PROJECT.SERVICEOWNERNAME IS 'Service Owner Name';

COMMENT ON COLUMN PROJECT.COUNTRY IS 'Country';

===============================================================================
CREATE TABLE TEAMLEAD 
(
  TLID NUMBER NOT NULL 
, TLNAME VARCHAR2(20) NOT NULL 
, TKID NUMBER  NOT NULL 
, TOTAL_REPORTIES NUMBER NOT NULL 
, ESCALATION1 VARCHAR2(20) 
, CONSTRAINT TEAMLEAD_PK PRIMARY KEY 
  (
    TLID 
  )
  ENABLE 
);

COMMENT ON COLUMN TEAMLEAD.TLID IS 'Team Lead Id';

COMMENT ON COLUMN TEAMLEAD.TLNAME IS 'Team Lead Name';

COMMENT ON COLUMN TEAMLEAD.TKID IS 'Task Id PK to Task table';

COMMENT ON COLUMN TEAMLEAD.TOTAL_REPORTIES IS 'Total Number of Reporties';

COMMENT ON COLUMN TEAMLEAD.ESCALATION1 IS 'ESCALATION 1';

===============================================================================
CREATE TABLE TEAMMEMBER 
(
  TMEMID NUMBER NOT NULL 
, TMEMNAME VARCHAR2(20) NOT NULL 
, TMEMEMAILID VARCHAR2(20) NOT NULL 
, TMEMPHONE VARCHAR2(20) NOT NULL 
, TLID NUMBER  NOT NULL 
, CONSTRAINT TEAMMEMBER_PK PRIMARY KEY 
  (
    TMEMID 
  )
  ENABLE 
);

COMMENT ON COLUMN TEAMMEMBER.TMEMID IS 'TEAM Member ID';

COMMENT ON COLUMN TEAMMEMBER.TMEMNAME IS 'TEAM Member NAME';

COMMENT ON COLUMN TEAMMEMBER.TMEMEMAILID IS 'TEAM Member EMAILID';

COMMENT ON COLUMN TEAMMEMBER.TMEMPHONE IS 'TEAM Member PHONE';

COMMENT ON COLUMN TEAMMEMBER.TLID IS 'Team Lead ID PK to TeamLead Table';



===============================================================================
CREATE TABLE LOGIN 
(
  LOGINID NUMBER NOT NULL 
, USERNAME VARCHAR2(20) NOT NULL 
, USERPASSWORD VARCHAR2(20) NOT NULL 
, PRJID NUMBER  NOT NULL 
, CONSTRAINT LOGIN_PK PRIMARY KEY 
  (
    USERNAME 
  )
  ENABLE 
);

COMMENT ON COLUMN LOGIN.LOGINID IS 'Login ID of User';

COMMENT ON COLUMN LOGIN.USERNAME IS 'Login User Name';

COMMENT ON COLUMN LOGIN.USERPASSWORD IS 'Login User Password';

COMMENT ON COLUMN LOGIN.PRJID IS 'Login User Projet Id';

===============================================================================
CREATE TABLE TASK 
(
  TKID NUMBER NOT NULL 
, TKNAME VARCHAR2(20) NOT NULL 
, STATUS VARCHAR2(20) NOT NULL 
, TMEMID NUMBER  NOT NULL 
, SPRINTID NUMBER  NOT NULL 
, TASKSTARTDATE VARCHAR2(20) NOT NULL 
, TASKENDDATE VARCHAR2(20) NOT NULL 
, CONSTRAINT TASK_PK PRIMARY KEY 
  (
    TKID 
  )
  ENABLE 
);

COMMENT ON COLUMN TASK.TKID IS 'Task ID OF USER';

COMMENT ON COLUMN TASK.TKNAME IS 'Task NAME';

COMMENT ON COLUMN TASK.STATUS IS 'Task STATUS';

COMMENT ON COLUMN TASK.TASKSTARTDATE IS 'Task Start Date';

COMMENT ON COLUMN TASK.TASKENDDATE IS 'Task End Date';

COMMENT ON COLUMN TASK.TMEMID IS 'ID of Task assigned to team member';

COMMENT ON COLUMN TASK.SPRINTID IS 'Task sprint Id  PK to Scrum';


===============================================================================
CREATE TABLE SCRUM 
(
  SCRUMID NUMBER NOT NULL 
, SCRUMNAME VARCHAR2(20) NOT NULL 
, SCRUMDESCRIPTION VARCHAR2(20) NOT NULL 
, PRJID NUMBER  NOT NULL 
, CONSTRAINT SCRUM_PK PRIMARY KEY 
  (
    SCRUMID 
  )
  ENABLE 
);

COMMENT ON COLUMN SCRUM.SCRUMID IS 'Scrum ID OF USER';

COMMENT ON COLUMN SCRUM.SCRUMNAME IS 'Scrum NAME';

COMMENT ON COLUMN SCRUM.SCRUMDESCRIPTION IS 'Scrum Descriptions';

COMMENT ON COLUMN SCRUM.PRJID IS 'Project Id PK to Project';



===============================================================================
CREATE TABLE SPRINT 
(
  SPRINTID NUMBER NOT NULL 
, SPRINTNAME VARCHAR2(20) NOT NULL 
, SCRUMID NUMBER  NOT NULL 
, SPRINTSTARTDATE VARCHAR2(20) NOT NULL 
, SPRINTENDDATE VARCHAR2(20) NOT NULL 
, CONSTRAINT SPRINT_PK PRIMARY KEY 
  (
    SPRINTID 
  )
  ENABLE 
);

COMMENT ON COLUMN SPRINT.SPRINTID IS 'SPRINT ID OF USER';

COMMENT ON COLUMN SPRINT.SPRINTNAME IS 'SPRINT NAME';

COMMENT ON COLUMN SPRINT.SPRINTSTARTDATE IS 'SPRINT start date';

COMMENT ON COLUMN SPRINT.SPRINTENDDATE IS 'SPRINT end Date';

COMMENT ON COLUMN SPRINT.SCRUMID IS 'SPRINT scrum Id PK to Scrum Table';


===============================================================================
CREATE TABLE RETROSPECT 
(
  RETID NUMBER NOT NULL 
, COMMENTS  VARCHAR2(20) NOT NULL 
, SPRINTNAME  VARCHAR2(20) NOT NULL 
, SPRINTID NUMBER  NOT NULL 
, CONSTRAINT RETROSPECT_PK PRIMARY KEY 
  (
    RETID 
  )
  ENABLE 
);

COMMENT ON COLUMN RETROSPECT.RETID IS 'Retrospect ID';

COMMENT ON COLUMN RETROSPECT.COMMENTS IS 'Retrospect Comments';

COMMENT ON COLUMN RETROSPECT.SPRINTNAME IS 'Retrospect Sprint name';

COMMENT ON COLUMN RETROSPECT.SPRINTID IS 'Retrospect Team Sprint Id PK to Sprint';

===========================================================================================

CREATE TABLE KPI 
(
  KPIID NUMBER NOT NULL 
, SPRINTID  VARCHAR2(20) NOT NULL 
, SPRINTNAME  VARCHAR2(20) NOT NULL 
, DEFECTDENSITY NUMBER  NOT NULL 
, SCHEDULE_SLIPPAGE NUMBER  NOT NULL 
, DESIGN_REVIEW_COVERAGE NUMBER  NOT NULL 
, CODE_REVIEW_COVERAGE NUMBER  NOT NULL 
, TEST_CASE_COVERAGE NUMBER  NOT NULL 
, CONSTRAINT KPI_PK PRIMARY KEY 
  (
    KPIID 
  )
  ENABLE 
);

COMMENT ON COLUMN KPI.KPIID IS 'KPI ID';

COMMENT ON COLUMN KPI.SPRINTID IS 'KPI Sprint ID';

COMMENT ON COLUMN KPI.SPRINTNAME IS 'KPI Sprint name';

COMMENT ON COLUMN KPI.DEFECTDENSITY IS 'KPI Defect Density';

COMMENT ON COLUMN KPI.SCHEDULE_SLIPPAGE IS 'KPI Schedule Sclippage';

COMMENT ON COLUMN KPI.DESIGN_REVIEW_COVERAGE IS 'KPI Design Review';

COMMENT ON COLUMN KPI.CODE_REVIEW_COVERAGE IS 'KPI Code Review Coverage';

COMMENT ON COLUMN KPI.TEST_CASE_COVERAGE IS 'KPI Test Case Coverage';

====================================

CREATE TABLE SCRUMROLE 
(
  SRID NUMBER NOT NULL 
, SRNAME  VARCHAR2(20) NOT NULL 
, CONSTRAINT SCRUMROLE_PK PRIMARY KEY 
  (
    SRID 
  )
  ENABLE 
);

COMMENT ON COLUMN SCRUMROLE.SRID IS 'SCRUMROLE ID';

COMMENT ON COLUMN SCRUMROLE.SRNAME IS 'SCRUMROLE Name';

==========================

CREATE TABLE SCRUMROLERESPONSIBILITY 
(
  SRRID NUMBER NOT NULL
, SRID NUMBER NOT NULL   
, RR VARCHAR2(20) NOT NULL 
, CONSTRAINT SCRUMROLERESPONSIBILITY_PK PRIMARY KEY 
  (
    SRRID 
  )
  ENABLE 
);

COMMENT ON COLUMN SCRUMROLERESPONSIBILITY.SRRID IS 'SCRUMROLERESPONSIBILITY ID';

COMMENT ON COLUMN SCRUMROLERESPONSIBILITY.SRID IS 'SCRUMROLERESPONSIBILITY Scrum Role ID';

COMMENT ON COLUMN SCRUMROLERESPONSIBILITY.RR IS 'SCRUMROLERESPONSIBILITY Responsibilities';
=================================

CREATE TABLE CHECKLIST 
(
  CLID NUMBER NOT NULL
, CLLID NUMBER NOT NULL   
, CLDESCRIPTION VARCHAR2(20) NOT NULL 
, CONSTRAINT CHECKLIST_PK PRIMARY KEY 
  (
    CLID 
  )
  ENABLE 
);

COMMENT ON COLUMN CHECKLIST.CLID IS 'CHECKLIST ID';

COMMENT ON COLUMN CHECKLIST.CLLID IS 'CHECKLIST Item Id';

COMMENT ON COLUMN CHECKLIST.CLDESCRIPTION IS 'CHECKLIST Descriptions';


=====================


CREATE TABLE CHECKLISTITEM 
(
  CLIID NUMBER NOT NULL
, CLIDESCRIPTION VARCHAR2(20) NOT NULL 
, CONSTRAINT CHECKLISTITEM_PK PRIMARY KEY 
  (
    CLIID 
  )
  ENABLE 
);

COMMENT ON COLUMN CHECKLISTITEM.CLIID IS 'CHECKLISTIteam ID';


COMMENT ON COLUMN CHECKLISTITEM.CLIDESCRIPTION IS 'CHECKLISTIteam Descriptions';

===========================

CREATE TABLE SCRUMKNOWLEDGE 
(
  SKID NUMBER NOT NULL
, TOPICID NUMBER NOT NULL   
, TOPICDESCRIPTIONS VARCHAR2(20) NOT NULL 
, CONSTRAINT SCRUMKNOWLEDGE_PK PRIMARY KEY 
  (
    SKID 
  )
  ENABLE 
);

COMMENT ON COLUMN SCRUMKNOWLEDGE.SKID IS 'SCRUMKNOWLEDGE ID';

COMMENT ON COLUMN SCRUMKNOWLEDGE.TOPICID IS 'SCRUMKNOWLEDGE Topic ID';

COMMENT ON COLUMN SCRUMKNOWLEDGE.TOPICDESCRIPTIONS IS 'SCRUMKNOWLEDGE Topic Descriptions';
====================================



INSERT INTO "ANDROID"."LOGIN" (LOGINID, USERNAME, USERPASSWORD, PRJID) VALUES ('1', 'un', 'up', '1');
INSERT INTO "ANDROID"."PROJECT" (PRJID, PRJNAME, ESCALATION1, ESCALATION2, ESCALATION3, SERVICEOWNERNAME, COUNTRY) VALUES ('1', 'projectname1', 'eescallation1', 'escallation2', 'escallation3', 'sserviceownwername1', 'c1');
INSERT INTO "ANDROID"."RETROSPECT" (RETID, COMMENTS, SPRINTNAME, SPRINTID) VALUES ('1', 'ret1comments', 'sprint1', '1');
INSERT INTO "ANDROID"."RETROSPECT" (RETID, COMMENTS, SPRINTNAME, SPRINTID) VALUES ('2', 'ret2comments', 'sprint2', '2');
INSERT INTO "ANDROID"."RETROSPECT" (RETID, COMMENTS, SPRINTNAME, SPRINTID) VALUES ('3', 'ret3comments', 'sprint3', '3');


INSERT INTO "ANDROID"."SCRUM" (SCRUMID, SCRUMNAME, SCRUMDESCRIPTION, PRJID) VALUES ('1', 'scrumname1', 'scrum1description', '1');
INSERT INTO "ANDROID"."SCRUM" (SCRUMID, SCRUMNAME, SCRUMDESCRIPTION, PRJID) VALUES ('2', 'sscrumname2', 'scrum2description', '1');

INSERT INTO "ANDROID"."SPRINT" (SPRINTID, SPRINTNAME, SCRUMID, SPRINTSTARTDATE, SPRINTENDDATE) VALUES ('1', 'sprint1', '1', '18-April-2016', '6-May-2016')
INSERT INTO "ANDROID"."SPRINT" (SPRINTID, SPRINTNAME, SCRUMID, SPRINTSTARTDATE, SPRINTENDDATE) VALUES ('2', 'sprint2', '1', '18-April-2016', '6-May-2016')
INSERT INTO "ANDROID"."SPRINT" (SPRINTID, SPRINTNAME, SCRUMID, SPRINTSTARTDATE, SPRINTENDDATE) VALUES ('3', 'sprint3', '1', '18-April-2016', '6-May-2016')

INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('1', 'taskname1', 'complete', '1', '1', '18-April-2016', '19-April-2016')
INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('2', 'taskname1', 'inprogress', '2', '1', '27-April-2016', '30-April-2016')
INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('3', 'taskname1', 'open', '3', '1', '3-May-2016', '5-May-2016')

INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('4', 'taskname2', 'complete', '1', '2', '18-April-2016', '19-April-2016')
INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('5', 'taskname2', 'inprogress', '2', '2', '27-April-2016', '30-April-2016')
INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('6', 'taskname2', 'open', '3', '2', '3-May-2016', '5-May-2016')

INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('7', 'taskname3', 'complete', '1', '3', '18-April-2016', '19-April-2016')
INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('8', 'taskname3', 'inprogress', '2', '3', '27-April-2016', '30-April-2016')
INSERT INTO "ANDROID"."TASK" (TKID, TKNAME, STATUS, TMEMID, SPRINTID, TASKSTARTDATE, TASKENDDATE) VALUES ('9', 'taskname3', 'open', '3', '3', '3-May-2016', '5-May-2016')

INSERT INTO "ANDROID"."TEAMLEAD" (TLID, TLNAME, TKID, TOTAL_REPORTIES, ESCALATION1) VALUES ('1', 'teamlead1', '1', '5', 'escallationteamlead1');
INSERT INTO "ANDROID"."TEAMLEAD" (TLID, TLNAME, TKID, TOTAL_REPORTIES, ESCALATION1) VALUES ('2', 'teamlead2', '2', '5', 'escallationteamlead1');
INSERT INTO "ANDROID"."TEAMLEAD" (TLID, TLNAME, TKID, TOTAL_REPORTIES, ESCALATION1) VALUES ('3', 'teamlead3', '3', '5', 'escallationteamlead1');



INSERT INTO "ANDROID"."TEAMMEMBER" (TMEMID, TMEMNAME, TMEMEMAILID, TMEMPHONE, TLID) VALUES ('1', 'teammember1', 'teammember1@test.com', '123456', '1')
INSERT INTO "ANDROID"."TEAMMEMBER" (TMEMID, TMEMNAME, TMEMEMAILID, TMEMPHONE, TLID) VALUES ('2', 'teammember2', 'teammember2@test.com', '5678902', '1')
INSERT INTO "ANDROID"."TEAMMEMBER" (TMEMID, TMEMNAME, TMEMEMAILID, TMEMPHONE, TLID) VALUES ('3', 'teammember3', 'teammember3@test.com', '22345', '2')
INSERT INTO "ANDROID"."TEAMMEMBER" (TMEMID, TMEMNAME, TMEMEMAILID, TMEMPHONE, TLID) VALUES ('4', 'teammember4', 'teammember4@test.com', '33222', '2')
INSERT INTO "ANDROID"."TEAMMEMBER" (TMEMID, TMEMNAME, TMEMEMAILID, TMEMPHONE, TLID) VALUES ('5', 'teammember5', 'teammember5@test.com', '44433', '3')


INSERT INTO "ANDROID"."KPI" (KPIID, SPRINTID, SPRINTNAME, DEFECTDENSITY, SCHEDULE_SLIPPAGE, DESIGN_REVIEW_COVERAGE, CODE_REVIEW_COVERAGE, TEST_CASE_COVERAGE) VALUES ('1', '1', 'sprint1', '1', '1', '1', '1', '1')
INSERT INTO "ANDROID"."KPI" (KPIID, SPRINTID, SPRINTNAME, DEFECTDENSITY, SCHEDULE_SLIPPAGE, DESIGN_REVIEW_COVERAGE, CODE_REVIEW_COVERAGE, TEST_CASE_COVERAGE) VALUES ('2', '2', 'sprint2', '22', '21', '21', '21', '2')
INSERT INTO "ANDROID"."KPI" (KPIID, SPRINTID, SPRINTNAME, DEFECTDENSITY, SCHEDULE_SLIPPAGE, DESIGN_REVIEW_COVERAGE, CODE_REVIEW_COVERAGE, TEST_CASE_COVERAGE) VALUES ('3', '3', 'sprint3', '3', '33', '3', '31', '32')
INSERT INTO "ANDROID"."SCRUMROLE" (SRID, SRNAME) VALUES ('1', 'PRODUCT OWNER')
INSERT INTO "ANDROID"."SCRUMROLE" (SRID, SRNAME) VALUES ('2', 'SCRUMMASTER')
INSERT INTO "ANDROID"."SCRUMROLE" (SRID, SRNAME) VALUES ('3', 'DEVELOPMENTTEAM')
INSERT INTO "ANDROID"."SCRUMROLERESPONSIBILITY" (SRRID, SRID, RR) VALUES ('1', '1', 'RR1')
INSERT INTO "ANDROID"."SCRUMROLERESPONSIBILITY" (SRRID, SRID, RR) VALUES ('2', '1', 'RR2')
INSERT INTO "ANDROID"."CHECKLIST" (CLID, CLLID, CLDESCRIPTION) VALUES ('1', '1', 'CL1')
INSERT INTO "ANDROID"."CHECKLIST" (CLID, CLLID, CLDESCRIPTION) VALUES ('2', '1', 'CL2')

INSERT INTO "ANDROID"."SCRUMKNOWLEDGE" (SKID, TOPICID, TOPICDESCRIPTIONS) VALUES ('1', '1', 'topic1')
INSERT INTO "ANDROID"."SCRUMKNOWLEDGE" (SKID, TOPICID, TOPICDESCRIPTIONS) VALUES ('2', '1', 'topic2')

INSERT INTO "ANDROID"."CHECKLISTITEM" (CLIID, CLIDESCRIPTION) VALUES ('1', 'Item 1')
INSERT INTO "ANDROID"."CHECKLISTITEM" (CLIID, CLIDESCRIPTION) VALUES ('2', 'Item 2')


How to create your own schema in Oracle 11G


login using sys
i.e. / as sysdba

CREATE BIGFILE TABLESPACE tbs_perm_android_01
DATAFILE 'tbs_perm_android_01.dat'
SIZE 10M
AUTOEXTEND ON;

CREATE TEMPORARY TABLESPACE tbs_temp_android_01
TEMPFILE 'tbs_temp_android_01.dbf'
SIZE 5M
AUTOEXTEND ON;


CREATE USER android
IDENTIFIED BY android
DEFAULT TABLESPACE tbs_perm_android_01
TEMPORARY TABLESPACE tbs_temp_android_01
QUOTA 20M on tbs_perm_android_01;

GRANT create session TO android;
GRANT create table TO android;
GRANT create view TO android;
GRANT create any trigger TO android;
GRANT create any procedure TO android;
GRANT create sequence TO android;
GRANT create synonym TO android;

Tuesday, April 19, 2016

Servlet example to perform Edit, Add operation on File

Requirement :- User has a course and can add course in it dependend on other. User can edit also the same course. Text file can have commented code like starting with # in the text file, So neglect such tile
Following are the servlet code
1:- ReadTextFileServlet
package com.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Vector;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ReadTextFileServlet extends HttpServlet {
//Vector av = new Vector();
HtmlUtils hu = new HtmlUtils();
PrintWriter out;
ServletContext context;
String filename = "/WEB-INF/Course1.txt";
/* protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
// We are going to read a file called configuration.properties. This
// file is placed under the WEB-INF directory.
String filename = "/WEB-INF/Course.txt";
ServletContext context = getServletContext();
// First get the file InputStream using ServletContext.getResourceAsStream()
// method.
InputStream is = context.getResourceAsStream(filename);
if (is != null) {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr);
PrintWriter writer = response.getWriter();
String text;
// We read the file line by line and later will be displayed on the
// browser page.
while ((text = reader.readLine()) != null) {
writer.println(text + "");
}
}
}*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
printTable(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
printTable(request, response);
}
public void printTable(HttpServletRequest request,
HttpServletResponse response) throws IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
Vector av = new Vector();
out.print(hu.createHtmlHeader("Print Table"));
out.print(hu.getTableHead("center", 1));
out.print(hu.getTH("center", "Code"));
out.print(hu.getTH("center", "Title"));
out.print(hu.getTH("center", "Prerequisites"));
out.print(hu.getTH("center", "Operation"));
ServletContext context = getServletContext();
InputStream is = context.getResourceAsStream(filename);
if (is != null) {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr);
//PrintWriter writer = response.getWriter();
String text;
while ((text = reader.readLine()) != null) {
if(text.length() > 0 && text.trim().indexOf('#') != 0) {
//writer.println(text + "");
String[] sArray = text.split(",",0);
if(sArray.length==1)
{
String parameter = "";
for(int i=0;iav.addElement(sArray[0]);
parameter = sArray[0];
}
av.addElement("");
av.addElement("");
av.addElement("Edit");
}else if (sArray.length==2)
{
String parameter1 = "";
for(int i=0;iav.addElement(sArray[i]);
parameter1 = parameter1 + "-" + sArray[i];
}
av.addElement("");
av.addElement("Edit");
}else
{
String parameter2 = "";
for(int i=0;iav.addElement(sArray[i]);
parameter2 = parameter2 + "-" +sArray[i];
}
av.addElement("Edit");
}
}
}
}
out.print(hu.getTableContents("center", av, 4));
out.print(hu.getTR());
out.print(hu.getTD());
out.println("Add Course");
out.print(hu.getClosedTD());
out.print(hu.getClosedTR());
out.print(hu.getHtmlFooter());

}

class HtmlUtils {
public String createHtmlHeader(String title) {
String htmlHeader = null;
htmlHeader = " " + title + " ";
return htmlHeader;
}
public String getHtmlFooter() {
String htmlFooter = "
";
return htmlFooter;
}
public String getHead(int level, String heading) {
return " " + heading + "";
}
public String getTableHead(String align, int border) {
String tableHeader = null;
tableHeader = "";
return tableHeader;
}
public String getTR(String align) {
String TRCell = null;
TRCell = " ";
return TRCell;
}
public String getTR() {
String TRCell = null;
TRCell = " ";
return TRCell;
}
public String getTD(String align, String value) {
String TDCell = null;
TDCell = "

" + value + "
";
return TDCell;
}
public String getTD() {
String TDCell = null;
TDCell = "

";
return TDCell;
}
public String getTD(int width) {
String TDCell = null;
TDCell = "

";
return TDCell;
}
public String getTH(String align, String value) {
String THCell = null;
THCell = "

" + value + "
";
return THCell;
}
public String getTableContents(String align, Vector values, int elementCounter) throws IOException {
StringWriter Cells = new StringWriter();
String contents = new String();
int vsize = values.size();
Cells.write(" ");
for (int i = 0; i < vsize; i++) {
String value = values.elementAt(i).toString();
if (i != 0) {
if (i >= elementCounter) {
if (i % elementCounter == 0) {
Cells.write("
\n\n ");
}
}
}
Cells.write("
" + value + "
\n");
}
Cells.write("
");
contents = Cells.toString();
Cells.flush();
Cells.close();
return contents;
}
public String getClosedTR() {
String TRCell = null;
TRCell = "
";
return TRCell;
}
public String getClosedTD() {
String TDCell = null;
TDCell = "
";
return TDCell;
}
public String getBR(int lines) {
StringWriter lineBR = new StringWriter();
String lineBRs = new String();
for (int i = 0; i <= lines; i++) {
lineBR.write("
\n");
}
lineBRs = lineBR.toString();
return lineBRs;
}
public String getLI(String item) {
String li = new String("


  • ");
    li += item;
    return li;
  • }
    }
    }

    2:- AddCourseTextFileServlet
    package com.test;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.util.Vector;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class AddCourseTextFileServlet extends HttpServlet {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    Vector av = new Vector();
    ServletContext context;
    String filename = "/WEB-INF/Course1.txt";
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    context = getServletContext();
    printTable(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    //printTable(request, response);
    String finalCheckBox="";
    PrintWriter out = response.getWriter();
    String button1Click = request.getParameter("Submit");
    System.out.println("button1Click"+button1Click);
    File outputFile = new File(getServletContext().getRealPath("/WEB-INF/")
    + "/Course1.txt");
    FileWriter fout = new FileWriter(outputFile,true);

    try {
    InputStream is = context.getResourceAsStream(filename);
    if (is != null) {
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader reader = new BufferedReader(isr);

    String text;
    int k=0;
    while ((text = reader.readLine()) != null) {
    if(text.length() > 0 && text.trim().indexOf('#') != 0) {
    k = k +1 ;
    String[] sArray = text.split(",",2);
    String [] checkboxNamesList = new String[sArray.length];

    for(int i=0;i{
    checkboxNamesList= request.getParameterValues(sArray[i]);
    if(null != checkboxNamesList)
    {
    finalCheckBox = finalCheckBox + sArray[i].toString() + " ";
    }
    else
    {
    finalCheckBox = finalCheckBox;
    }

    }
    }
    }
    System.out.println("Value of record is:"+k);
    }
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    String finalString = request.getParameter("Code") + "," + request.getParameter("Title") + "," + finalCheckBox;
    fout.write("\n");
    fout.write(finalString);
    fout.close();
    RequestDispatcher rd = request.getRequestDispatcher("readTextFileServlet");
    rd.forward(request,response);

    }

    public void printTable(HttpServletRequest request,
    HttpServletResponse response) throws IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("");
    out.println("");
    out.println(" Add Course ");
    out.println("");
    out.println("");
    out.println("
    ");
    out.println("");
    out.println("
    Code:
    ");
    out.println("
    ");
    out.println(" ");
    out.println("
    Title:
    ");
    out.println("
    ");
    out.println(" ");
    out.println("
    Prerequisite(s):
    ");
    try {
    InputStream is = context.getResourceAsStream(filename);
    if (is != null) {
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader reader = new BufferedReader(isr);
    String text;
    int k=0;
    while ((text = reader.readLine()) != null) {
    if(text.length() > 0 && text.trim().indexOf('#') != 0) {
    //writer.println(text + "");
    k = k +1 ;
    String[] sArray = text.split(",",2);
    out.print("
    ");
    for(int i=0;i{
    out.print("");
    out.print(" ");
    //out.print(" ");


    out.print("
    ");
    out.print("
    ");
    out.println("
    ");
    out.print(sArray[i].toString());
    out.print("
    ");
    }
    out.print("

    ");

    }
    }
    System.out.println("Value of record is:"+k);
    }
    out.println("


    ");
    out.println("
    ");
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    out.println("
    ");
    out.println("
    ");

    }
    }

    3:- EditCourseTextFileServlet
    package com.test;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.util.Vector;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class EditCourseTextFileServlet extends HttpServlet {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    Vector av = new Vector();
    ServletContext context;
    String filename = "/WEB-INF/Course1.txt";
    String sUrlParam="";

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    context = getServletContext();
    printTable(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    //printTable(request, response); //To Lead the table as per the data available from URL
    request.setAttribute("param",sUrlParam);
    RequestDispatcher rd = request.getRequestDispatcher("editSaveCourseTextFileServlet");
    rd.forward(request,response);
    }

    public void printTable(HttpServletRequest request,
    HttpServletResponse response) throws IOException {
    response.setContentType("text/html");
    sUrlParam = request.getParameter("param");
    PrintWriter out = response.getWriter();
    out.println("");
    out.println("");
    out.println(" Edit Course ");
    out.println("");
    out.println("");
    out.println("
    ");
    out.println("");
    String[] urlArray = sUrlParam.split("-",0);
    //for(int i=0;iif(urlArray.length > 0)
    {
    //System.out.println(urlArray[i]);
    if((urlArray.length == 2 || urlArray.length == 3) && urlArray[0] != null)
    {
    out.println("

    Code:
    ");
    out.println("
    ");
    out.println(" ");
    }
    if((urlArray.length == 2 || urlArray.length == 3) && urlArray[1] != null)
    {
    out.println(" Title:
    ");
    String textValue = urlArray[1].trim();//.toString().replaceAll(" ", " ");
    out.println("
    ");
    out.println(" ");
    }
    if(urlArray.length == 3 && urlArray[2]!= null)
    {
    //Showing all Check Box
    InputStream is = context.getResourceAsStream(filename);
    if (is != null) {
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader reader = new BufferedReader(isr);
    String text;
    out.println("

    Prerequisite(s):
    ");
    out.print("");
    String checkBoxString = urlArray[2].trim().toString();
    String[] sArray1 = checkBoxString.split(" ",0);
    out.print("
    ");
    while ((text = reader.readLine()) != null) {
    if(text.length() > 0 && text.trim().indexOf('#') != 0) {
    //writer.println(text + "");
    String[] sArray = text.split(",",2);
    for(int i=0;i{
    out.print(" ");
    //cheking if the check box need to clicked start[
    boolean flag = false;
    for(int m=0;mif(sArray[i].toString().equals(sArray1[m].toString()))
    {
    out.println("

    ");
    out.print(sArray[i].toString());
    flag = true;
    }
    }
    //cheking if the check box need to clicked end]
    if(!flag)
    {
    out.println("
    ");
    out.print(sArray[i].toString());
    flag= false;

    }
    out.print("
    ");
    out.print("");
    }
    }
    }
    out.print("");
    out.print("");
    }
    }
    else
    {
    try {
    InputStream is = context.getResourceAsStream(filename);
    if (is != null) {
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader reader = new BufferedReader(isr);
    String text;
    int k=0;
    out.println("

    Prerequisite(s):
    ");
    while ((text = reader.readLine()) != null) {
    if(text.length() > 0 && text.trim().indexOf('#') != 0) {
    //writer.println(text + "");
    k = k +1 ;
    String[] sArray = text.split(",",2);
    out.print("
    ");
    for(int i=0;i{
    out.print("");
    out.print(" ");
    //out.print(" ");


    out.print("
    ");
    out.print("
    ");
    out.println("
    ");
    out.print(sArray[i].toString());
    out.print("
    ");
    }
    out.print("

    ");
    }
    }
    out.print("
    ");
    System.out.println("Value of record is:"+k);
    }
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    out.println("


    ");
    out.println("
    ");
    out.println("");
    out.println("
    ");
    }
    }
    }
    4:- EditSaveCourseTextFileServlet
    package com.test;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.util.Vector;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class EditSaveCourseTextFileServlet extends HttpServlet {
    /**
    *
    */
    private static final long serialVersionUID = 1L;
    Vector av = new Vector();
    ServletContext context;
    String filename = "/WEB-INF/Course1.txt";
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    context = getServletContext();
    }

    private void updateLine(String toUpdate, String updated) throws IOException {
    InputStream is = context.getResourceAsStream(filename);
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader file = new BufferedReader(isr);
    String my_new_str = toUpdate.replaceAll("-", ",");
    String line;
    String input = "";
    while ((line = file.readLine()) != null)
    input += line + "\n";
    input = input.replace(my_new_str, updated);
    File outputFile = new File(getServletContext().getRealPath("/WEB-INF/")
    + "/Course1.txt");
    //FileWriter fout = new FileWriter(outputFile,true);
    FileOutputStream os = new FileOutputStream(outputFile);
    os.write(input.getBytes());
    file.close();
    os.close();
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    String sOldValue = ""+request.getAttribute("param");

    //printTable(request, response);
    String finalCheckBox="";
    PrintWriter out = response.getWriter();
    String button1Click = request.getParameter("Submit");
    System.out.println("button1Click"+button1Click);
    File outputFile = new File(getServletContext().getRealPath("/WEB-INF/")
    + "/Course1.txt");
    FileWriter fout = new FileWriter(outputFile,true);

    try {
    context = getServletContext();
    InputStream is = context.getResourceAsStream(filename);
    if (is != null) {
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader reader = new BufferedReader(isr);

    String text;
    int k=0;
    while ((text = reader.readLine()) != null) {
    if(text.length() > 0 && text.trim().indexOf('#') != 0) {
    k = k +1 ;
    String[] sArray = text.split(",",2);
    String [] checkboxNamesList = new String[sArray.length];

    for(int i=0;i{
    checkboxNamesList= request.getParameterValues(sArray[i]);
    if(null != checkboxNamesList)
    {
    finalCheckBox = finalCheckBox + sArray[i].toString() + " ";
    }
    else
    {
    finalCheckBox = finalCheckBox;
    }

    }
    }
    }
    System.out.println("Value of record is:"+k);
    }
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    String finalString = request.getParameter("Code") + "," + request.getParameter("Title") + "," + finalCheckBox;
    this.updateLine(sOldValue, finalString);
    RequestDispatcher rd = request.getRequestDispatcher("readTextFileServlet");
    rd.forward(request,response);
    }
    }

    5- web.xml


       



    6:- Course1.txt
    # This is commented line no need to read it

    Siddhu120,Comment 1
    Siddhu122,Comment 2
    Siddhu201,Comment 3
    Siddhu202,Comment 4,Siddhu120 Siddhu201
    Siddhu203,Comment 6,Siddhu202
    Siddhu320,Comment ,Siddhu120 Siddhu122 Siddhu203




    Image_2

    Image_3

    Image_4