Tuesday, March 17, 2015

write a program in c/c++ using opengl to implement the cohen sutherland line clipping algorithm







write a program in c/c++ using opengl to implement the cohen sutherland line clipping algorithm

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
#include<process.h>

int pixels[2][4];
float xn1,xn2,yn1,yn2,x3,y3,m;


void show_quadrant()
    {
    cleardevice();
    rectangle(120,40,320,240);
    rectangle(320,40,520,240);
    rectangle(120,240,320,440);
    rectangle(320,240,520,440);
    for(int i=130;i<=510;i+=10)
        {
        if(i==320)
        continue;
        outtextxy(i,237,"+");
        }
    for(i=50;i<=430;i+=10)
        {
        if(i==240)
        continue;
        outtextxy(317,i,"-");
        }
    outtextxy(310,230,"O");
    outtextxy(530,240,"X");
    outtextxy(320,450,"-Y");
    outtextxy(100,240,"-X");
    outtextxy(320,30,"Y");
    }

void su_co(int x1,int y1,int x2,int y2,int xmin,int ymin,int xmax,int ymax)
       {
          int i,j,fl;
          for(i=0;i<2;i++)
              for(j=0;j<4;j++)
                 pixels[i][j]=0;
          if(y1>ymax)
        pixels[0][0]=1;
          if(y1<ymin)
        pixels[0][1]=1;
          if(x1>xmax)
        pixels[0][2]=1;
          if(x1<xmin)
        pixels[0][3]=1;
          if(y2>ymax)
        pixels[1][0]=1;
          if(y2<ymin)
        pixels[1][1]=1;
          if(x2>xmax)
        pixels[1][2]=1;
          if(x2<xmin)
        pixels[1][3]=1;

          for(j=0;j<4;j++)
              {
         if(pixels[0][j]==0&&pixels[1][j]==0)
            continue;
        if(pixels[0][j]==1&&pixels[1][j]==1)
              {
                fl=3;
                break;
              }
        fl=2;
              }
          switch(fl)
        {
           case 1:
                        line(320+x1,240-y1,320+x2,240-y2);
                 break;

           case 3:
                 cout<<"\n\n\a\" Line Is Not Visible...:-(";
                 break;

           case 2:
                 m=(y2-y1)/(x2-x1);
                 xn1=x1;
            yn1=y1;
                 xn2=x2;
            yn2=y2;
            if(pixels[0][0]==1)
                       {
                  xn1=x1+(ymax-y1)/m;
                  yn1=ymax;
                       }
                 if(pixels[0][1]==1)
                       {
                  xn1=x1+(ymin-y1)/m;
                  yn1=ymin;
                       }
                 if(pixels[0][2]==1)
                       {
                  yn1=y1+(xmax-x1)*m;
                  xn1=xmax;
                       }
                 if(pixels[0][3]==1)
                       {
                  yn1=y1+(xmin-x1)*m;
                  xn1=xmin;
                       }
                 if(pixels[1][0]==1)
                       {
                  xn2=x2+(ymax-y2)/m;
                  yn2=ymax;
                       }
                 if(pixels[1][1]==1)
                       {
                  xn2=x2+(ymin-y2)/m;
                  yn2=ymin;
                       }
                 if(pixels[1][2]==1)
                       {
                  yn2=y2+(xmax-x2)*m;
                  xn2=xmax;
                       }
                 if(pixels[1][3]==1)
                       {
                  yn2=y2+(xmin-x2)*m;
                  xn2=xmin;
                       }
                 line(320+xn1,240-yn1,320+xn2,240-yn2);
                 break;
        }
       }


void midpt(int x1,int y1,int x2,int y2,int xmin,int ymin,int xmax,int ymax)
       {
          int fl=1;
          int i,j;
         int ox1=x1,ox2=x2,oy1=y1,oy2=y2;
          for(i=0;i<2;i++)
         for(j=0;j<4;j++)
                 pixels[i][j]=0;

          if(y1>ymax)
        pixels[0][0]=1;
          if(y1<ymin)
        pixels[0][1]=1;
          if(x1>xmax)
        pixels[0][2]=1;
          if(x1<xmin)
        pixels[0][3]=1;
          if(y2>ymax)
        pixels[1][0]=1;
          if(y2<ymin)
        pixels[1][1]=1;
          if(x2>xmax)
        pixels[1][2]=1;
          if(x2<xmin)
        pixels[1][3]=1;

          for(j=0;j<4;j++)
              {
         if(pixels[0][j]==0&&pixels[1][j]==0)
            continue;

         if(pixels[0][j]==1&&pixels[1][j]==1)
              {
                fl=3;
                break;
              }
        fl=2;
              }
          switch(fl)
              {
           case 1:
                 line(320+x1,240-y1,320+x2,240-y2);
                 break;

           case 3:
                 cout<<"\n\n\a\" Line Is Not Visible...:-(";
                 break;

           case 2:
                 xn1=x1;
            yn1=y1;
                 xn2=x2;
            yn2=y2;
                 fl=0;
                 x3=x1;
            y3=y1;
                 while(1)
                       {
     if(!(y1>ymax || y1<ymin || x1>xmax || x1<xmin) && (x3 || y3)!=0.1)
                    break;
                 x3=(x1+x2)/2;
                 y3=(y1+y2)/2;
     if(!(y3>ymax || y3<ymin || x3>xmax || x3<xmin))
                   fl=1;
                 else
                   fl=0;
                 if(fl)
                       {
                          x2=x3;
                          y2=y3;
                       }
                 else
                       {
                          x1=x3;
                          y1=y3;
                       }
                       }
                 xn1=x3;
                 yn1=y3;
                 fl=0;
                 x1=ox1;
                 x2=ox2;
                 y1=oy1;
                 y2=oy2;
                 x3=x2;
            y3=y2;
                 while(1)
                       {
     if(!(y2>ymax || y2<ymin || x2>xmax || x2<xmin) && (x3 || y3)!=0.1)
                    break;
                 x3=(x1+x2)/2;
                 y3=(y1+y2)/2;

     if(!(y3>ymax || y3<ymin || x3>xmax || x3<xmin))
                   fl=1;
                 else
                   fl=0;

                 if(fl)
                       {
                          x1=x3;
                          y1=y3;
                       }
                 else
                       {
                          x2=x3;
                          y2=y3;
                       }
                 }
             xn2=x3;
                 yn2=y3;
                 line(320+xn1,240-yn1,320+xn2,240-yn2);
                 break;
         }
       }

void show_message()
    {
    char *mess[]={"-","=","["," ","L","i","n","e"," ","C","l","i",
              "p","p","i","n","g"," ","]","=","-",};
    int xx=29,xxx=50,i,j;
    _setcursortype(_NOCURSOR);
    for(i=0,j=21;i<13,j>=11;i++,j--)
        {
        gotoxy(xx,1);
        cout<<mess[i];
        xx++;
        gotoxy(xxx,1);
        cout<<mess[j];
        xxx--;
        delay(50);
        }
    _setcursortype(_NORMALCURSOR);
    }


void main()
    {
    clrscr();
        int gd=DETECT,gm,i,j;
        int xmin,ymin,xmax,ymax,x1,y1,x2,y2;
        int choice,ed[20],num;
        show_message();
        cout<<"\n\n\t\t\" Enter The Co-Ordinates Of The Clipping Window.\"";
    cout<<"\n\n\t\t\" Enter X(min) & Y(min) \":=";
        cin>>xmin>>ymin;
    cout<<"\n\t\t\" Enter X(max) & Y(max) \":=";
        cin>>xmax>>ymax;

        cout<<"\n\t\t\" Enter The Co-Ordinates Of The Line.\"";
    cout<<"\n\n\t\t\" Enter X(1) & Y(1) \":=";
        cin>>x1>>y1;
    cout<<"\n\t\t\" Enter X(2) & Y(2) \":=";
        cin>>x2>>y2;
        clrscr();
        show_message();
    cout<<"\n\n\n\t\t1:==>\" Sutherland-Cohen \"";
    cout<<"\n\n\t\t2:==>\" Mid-Point Method \"";
    cout<<"\n\n\t\t3:==>\" Exit \"";
    cout<<"\n\n\t\t\" Enter Your Choice \":=";
    cin>>choice;
    switch(choice)
        {
        case 1:
            initgraph(&gd,&gm,"..\\bgi");
            clearviewport();
                show_quadrant();
                  line(320+xmin,240-ymin,320+xmin,240-ymax);
                  line(320+xmin,240-ymax,320+xmax,240-ymax);
                  line(320+xmax,240-ymax,320+xmax,240-ymin);
                  line(320+xmax,240-ymin,320+xmin,240-ymin);
            line (320+x1,240-y1,320+x2,240-y2);
                getch();
                cleardevice();
                show_quadrant();
                  line(320+xmin,240-ymin,320+xmin,240-ymax);
                  line(320+xmin,240-ymax,320+xmax,240-ymax);
                  line(320+xmax,240-ymax,320+xmax,240-ymin);
                  line(320+xmax,240-ymin,320+xmin,240-ymin);
            su_co(x1,y1,x2,y2,xmin,ymin,xmax,ymax);
            getch();
            break;

        case 2:
            initgraph(&gd,&gm,"..\\bgi");
            clearviewport();
                show_quadrant();
                  line(320+xmin,240-ymin,320+xmin,240-ymax);
                  line(320+xmin,240-ymax,320+xmax,240-ymax);
                  line(320+xmax,240-ymax,320+xmax,240-ymin);
                  line(320+xmax,240-ymin,320+xmin,240-ymin);
            line (320+x1,240-y1,320+x2,240-y2);
                getch();
                cleardevice();
                show_quadrant();
                  line(320+xmin,240-ymin,320+xmin,240-ymax);
                  line(320+xmin,240-ymax,320+xmax,240-ymax);
                  line(320+xmax,240-ymax,320+xmax,240-ymin);
                  line(320+xmax,240-ymin,320+xmin,240-ymin);
               midpt(x1,y1,x2,y2,xmin,ymin,xmax,ymax);
            getch();
            break;

        case 3:
            exit(0);

                default:
                    cout<<"\n\t\a\" Press A Valid Key...!!! \"";
                        getch();
                        main();
                        break;
        }
    closegraph();
        }

Monday, March 16, 2015

Write a Program using Servlet and JDBC for developing online application for students attendance management for MCA –V semester students of a computer science department. Make necessary assumptions and create appropriate databases.



Write a Program using Servlet and JDBC for developing online application for students attendance management for MCA –V semester students of a computer science department. Make necessary assumptions and create appropriate databases.


Ans.    File: AddNoticeAction.java
package com.live.action;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.live.dao.NoticeDAO;
import com.live.dao.ProfileDAO;
import com.live.dao.SecurityDAO;
import com.live.form.NoticeForm;

public class AddNoticeAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public AddNoticeAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    NoticeForm nf=new NoticeForm();
                    String target="";
                    boolean flag=false;
                    nf.setNotice(request.getParameter("notice"));
                    nf.setNotby(request.getParameter("notby"));
                    flag=new NoticeDAO().AddNotice(nf);
                   
                    if(flag)
                    {
                                    target="AddNotice.jsp";
                                    System.out.println("Success");
                    }             
                    else
                                    target="AddNotice.jsp";
                    RequestDispatcher rd=request.getRequestDispatcher(target);
                    rd.forward(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }
}

File: AddProjectDocAction.java
package com.live.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.live.dao.ProjectDAO;
import com.live.form.ProjectForm;

public class AddProjectDocAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public AddProjectDocAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    ProjectForm pf=new ProjectForm();
                    String target="";
                    boolean flag=false;
                    pf.setPdoc(request.getParameter("pdoc"));
                    pf.setTeamid(request.getParameter("user"));
                    pf.setPrjid(Integer.parseInt(request.getParameter("prjid")));
                    System.out.println("projinaction"+pf.getPrjid());
                    flag=new ProjectDAO().AddProjectDoc(pf);
                   
                    if(flag)
                    {
                                    target="AddProjectDocs.jsp";
                                    System.out.println("Success");
                    }             
                    else
                                    target="AddProjectDocs.jsp";
                    RequestDispatcher rd=request.getRequestDispatcher(target);
                    rd.forward(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }
}

File: AddProjectStatusAction.java
package com.live.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.live.dao.ProjectDAO;
import com.live.form.ProjectForm;

public class AddProjectStatusAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public AddProjectStatusAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    ProjectForm pf=new ProjectForm();
                    String target="";
                    boolean flag=false;
                    pf.setStatus(request.getParameter("status"));
                    pf.setPrjid(Integer.parseInt(request.getParameter("projname")));
                    pf.setPercent(Double.parseDouble(request.getParameter("percent")));
                    flag=new ProjectDAO().updateProjectStatus(pf);
                   
                    if(flag)
                    {
                                    target="AddProjectStatus.jsp";
                                    System.out.println("Success");
                    }             
                    else
                                    target="AddProjectStatus.jsp";
                    RequestDispatcher rd=request.getRequestDispatcher(target);
                    rd.forward(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }

}


File: AddTeamAction.java
package com.live.action;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.live.dao.ProfileDAO;
import com.live.dao.SecurityDAO;
import com.live.form.RegisterForm;

public class AddTeamAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public AddTeamAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {
                    RegisterForm rf=new RegisterForm();
                    String target="";
                    HttpSession sess=request.getSession();
                    boolean flag=false;
                    try{
                                    rf.setBatchno((String)sess.getAttribute("bno"));
                                    rf.setYear(Integer.parseInt((String)sess.getAttribute("year")));
                                    rf.setLoginname((String)sess.getAttribute("loginname"));
                                    rf.setPassword((String)sess.getAttribute("password"));
                                    rf.setUname((String)sess.getAttribute("uname"));
                                    rf.setPrjname((String)sess.getAttribute("prjname"));
                                    rf.setTechused((String)sess.getAttribute("techused"));
                                    rf.setSecretquestionid(Integer.parseInt(((String)sess.getAttribute("secretquestionid"))));
                                    rf.setOwnsecretquestion((String)sess.getAttribute("ownsecretquestion"));
                                    rf.setSecretanswer((String)sess.getAttribute("secretanswer"));
                                    rf.setLogintype("team");
                                   
                                    flag=new ProfileDAO().registration(rf);
                                   
                                    if(flag)
                                    {
                                                    Enumeration em=sess.getAttributeNames();
                                                    while(em.hasMoreElements())
                                                    {
                                                                    String dd=(String)em.nextElement();
                                                                    System.out.println("attrib"+dd);
                                                                    if(dd.equalsIgnoreCase("bno") || dd.equalsIgnoreCase("role") || dd.equalsIgnoreCase("year") || dd.equalsIgnoreCase("loginname") || dd.equalsIgnoreCase("password") || dd.equalsIgnoreCase("uname") || dd.equalsIgnoreCase("email") || dd.equalsIgnoreCase("prjname") || dd.equalsIgnoreCase("techused") || dd.equalsIgnoreCase("secretquestionid") || dd.equalsIgnoreCase("secretanswer") || dd.equalsIgnoreCase("ownsecretquestion") || dd.equalsIgnoreCase("projtype"))
                                                                    {
                                                                                    System.out.println("Sorry");
                                                                    }
                                                                    else{
                                                                                    //String did=(String)(em.nextElement());
                                                                                    String svar=(String)sess.getAttribute(dd);
                                                                    String s[]=svar.split(",");
                                                                    System.out.println("hiiii"+svar);
                                                                    String mname=s[0];
                                                                    String mail=s[1];
                                                                                    rf.setMname(mname);
                                                                                    rf.setMemail(mail);
                                                                                    rf.setRegdno(dd);
                                                                                    flag=new ProfileDAO().AddTeamMembers(rf);
                                                                    }
                                                    }                             
                                    }
                    }catch(Exception e)
                                    {e.printStackTrace();}
                                    if(flag)
                                    {
                                                    String user=(String)sess.getAttribute("user");
                                                    System.out.println("user"+user);
                                                    String role=null;
                                                    try {
                                                                    role=new SecurityDAO().getLoginType(user);
                                                                    System.out.println("role"+role);
                                                    } catch (SQLException e) {
                                                    // TODO Auto-generated catch block
                                                    e.printStackTrace();
                                    }
                                    sess.invalidate();
                                    HttpSession session=request.getSession();
                                    session.setAttribute("user",user);
                                    session.setAttribute("role", role);
                                    target="TeamRegister.jsp";
                    }             
                    else
                                    target="TeamRegister.jsp";
                    RequestDispatcher rd=request.getRequestDispatcher(target);
                    rd.forward(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }

}


File: AddTeamMembersAction.java
package com.live.action;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.live.dao.ProfileDAO;

public class AddTeamMembersAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public AddTeamMembersAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    boolean flag=false;
                    String target="";
                    response.setContentType("text/html");
                    HttpSession sess=request.getSession();
                   
                    if(request.getParameter("add").equalsIgnoreCase("ADD TEAM"))
                    {
                                    System.out.println("in session");
                                    String uname=request.getParameter("uname");
                                    System.out.println("insdfdsaf"+uname);
                                    String email=request.getParameter("email");
                                    String regdno=request.getParameter("regdno");
                                    String sesvar=uname+","+email;
                                    sess.setAttribute(regdno, sesvar);
                                   
                                    flag=true;
                    }
                   
                                    if(flag)
                                                    target="AddTeamMembers.jsp";
                                    else
                                                    target="AddTeamMembers.jsp";
                                    RequestDispatcher rd=request.getRequestDispatcher(target);
                                    rd.forward(request,response);
                    }
    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }

}

File: AddTimeSheetAction.java
package com.live.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AddTimeSheetAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public AddTimeSheetAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    boolean flag=false;
                    String target="";
                    response.setContentType("text/html");
                    HttpSession sess=request.getSession();
                    String tsdate="";
                    if(request.getParameter("add").equalsIgnoreCase("ADD TimeSheet"))
                    {
                                    System.out.println("in session");
                                    String hour=request.getParameter("hour");
                                    System.out.println("insdfdsaf"+hour);
                                    String work=request.getParameter("work");
                                    String status=request.getParameter("status");
                                    tsdate=request.getParameter("tdate");
                                    String sesvar1=work+","+status+","+tsdate;
                                    sess.setAttribute(hour, sesvar1);

                                    flag=true;
                    }
                   
                                    if(flag)
                                                    target="TimeSheet.jsp?tsdate="+tsdate;
                                    else
                                                    target="TimeSheet.jsp";
                                    RequestDispatcher rd=request.getRequestDispatcher(target);
                                    rd.forward(request,response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }

}

File: DBConn.java
package com.live.conn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import com.live.util.LoggerManager;
public class DBConn {
    public Connection con;
    private static Properties mProps;

   
    /**
     * @return the props
     */
    public Properties getProperties()
    {
                    return mProps;
    }

    /**
     * @param props
     *            application properties object
     */
    public void setProperties(Properties aProps)
    {
                    mProps = aProps;
    }

    public Connection getConnection()
    {
                    try
                    {
                                    Properties aProps = getProperties();
                                    System.out.println(aProps.getProperty("driver"));
                                    Class.forName(aProps.getProperty("driver"));
                                    con = DriverManager.getConnection(aProps.getProperty("url"), aProps.getProperty("duser"), aProps.getProperty("dpass"));
                                    System.out.println(con);
                                    System.out.println("Connection Established");
                    }
                    catch (ClassNotFoundException cnfe)
                    {
                                    LoggerManager.writeLogWarning(cnfe);
                    }
                    catch (SQLException se)
                    {
                                    LoggerManager.writeLogWarning(se);
                    }
                    return con;
                    }
                    public void releaseResources(Connection con,PreparedStatement ps)
                    {
                                    try
                                    {
                                                    if(con!=null)
                                                    {
                                                                    con.close();
                                                                    System.out.println("Connection Closed");
                                                    }
                                                    else
                                                    {
                                                                    con.close();
                                                    }
                                                    if(ps!=null)
                                                    {
                                                                    ps.close();
                                                                    System.out.println(" Prepare Connection Closed");
                                                    }
                                                    else
                                                    {
                                                                    ps.close();
                                                    }
                                    }
                                    catch(Exception e)
                                    {
                                                    e.printStackTrace();
                                    }
                    }
                   
                    public void releaseResources1(Connection con,Statement ps)
                    {
                                    try
                                    {
                                                    if(con!=null)
                                                    {
                                                                    con.close();
                                                    }
                                                    else
                                                    {
                                                                    con.close();
                                                    }
                                                    if(ps!=null)
                                                    {
                                                                    ps.close();
                                                    }
                                                    else
                                                    {
                                                                    ps.close();
                                                    }
                                    }
                                    catch(Exception e)
                                    {
                                                    e.printStackTrace();
                                    }
                    }


}

File: LoginAction.java
package com.live.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.live.dao.SecurityDAO;
import com.live.form.RegisterForm;

public class LoginAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public LoginAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    RegisterForm ef=new RegisterForm();
                    ef.setLoginname(request.getParameter("loginname"));
                    ef.setPassword(request.getParameter("password"));
                    String responsekey="LoginForm.jsp";
                    try{
                     String role=new SecurityDAO().loginCheck(ef);
         System.out.println("r"+role);
         HttpSession session=request.getSession();
         if(role.equalsIgnoreCase("admin"))
         {
                    responsekey="AdminHome.jsp";
            session.setAttribute("user",ef.getLoginname());
            session.setAttribute("role",role);
         }
         else if(role.equalsIgnoreCase("guide"))
         {
                     
                                     int status = new SecurityDAO().checkFirstLogin(ef.getLoginname());
                                     if(status==1)
                                     {
                                                     responsekey="GuideHomePage.jsp";
                                                     session.setAttribute("user",ef.getLoginname());
                                                     session.setAttribute("role",role);
                                     }
                     }
         else if(role.equalsIgnoreCase("team"))
         {
                     
                                     int status = new SecurityDAO().checkFirstLogin(ef.getLoginname());
                                     if(status==1)
                                     {
                                                     responsekey="TeamHomePage.jsp";
                                                     session.setAttribute("user",ef.getLoginname());
                                                     session.setAttribute("role",role);
                                     }
                     }
         //}
         else 
                     responsekey="LoginForm.jsp";
            }catch(Exception e){}
                                     System.out.println("responsekey"+responsekey);
                                    RequestDispatcher rd=request.getRequestDispatcher(responsekey);
                                    rd.forward(request,response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }

}

File: RegisterAction.java
package com.live.action;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.live.dao.ProfileDAO;
import com.live.form.RegisterForm;

public class RegisterAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public RegisterAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    RegisterForm rf=new RegisterForm();
                    String target="";
                    rf.setUname(request.getParameter("uname"));
                    rf.setLoginname(request.getParameter("loginname"));
                    rf.setPassword(request.getParameter("password"));
                    rf.setEmail(request.getParameter("email"));
                    rf.setSecretquestionid(Integer.parseInt(request.getParameter("secretquestionid")));
                    rf.setOwnsecretquestion(request.getParameter("ownsecretquestion"));
                    rf.setSecretanswer(request.getParameter("secretanswer"));
                    rf.setLogintype("guide");
                    try {
                                    boolean flag=new ProfileDAO().registration(rf);
                                    if(flag)
                                                    target="LoginForm.jsp";
                                    else
                                                    target="Register.jsp";
                                    RequestDispatcher rd=request.getRequestDispatcher(target);
                                    rd.forward(request,response);
                    } catch (SQLException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                    }
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }

}

File: SubmitTimeSheetAction.java
package com.live.action;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.live.dao.SecurityDAO;
import com.live.dao.TimeSheetDAO;
import com.live.form.TimeSheetForm;

public class SubmitTimeSheetAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public SubmitTimeSheetAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */h
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    String target="";
                    HttpSession sess=request.getSession();
                    boolean flag=false;
                    try{
                                                    TimeSheetForm tf=new TimeSheetForm();
                                                    Enumeration em=sess.getAttributeNames();
                                                    while(em.hasMoreElements())
                                                    {
                                                                    String dd=(String)em.nextElement();
                                                                    System.out.println("attrib"+dd);
                                                                    if(dd.equalsIgnoreCase("bno") || dd.equalsIgnoreCase("role") || dd.equalsIgnoreCase("year") || dd.equalsIgnoreCase("loginname") || dd.equalsIgnoreCase("password") || dd.equalsIgnoreCase("uname") || dd.equalsIgnoreCase("email") || dd.equalsIgnoreCase("prjname") || dd.equalsIgnoreCase("techused") || dd.equalsIgnoreCase("secretquestionid") || dd.equalsIgnoreCase("secretanswer") || dd.equalsIgnoreCase("ownsecretquestion") || dd.equalsIgnoreCase("projtype") || dd.equalsIgnoreCase("user"))
                                                                    {
                                                                                    System.out.println("Sorry");
                                                                    }
                                                                    else{
                                                                                    //String did=(String)(em.nextElement());
                                                                                    String user=(String)sess.getAttribute("user");
//                                                                                 String tsdate=request.getParameter("tsdate");
                                                                                    String svar=(String)sess.getAttribute(dd);
                                                                    String s[]=svar.split(",");
                                                                    System.out.println("hiiii"+svar);
                                                                    String work=s[0];
                                                                    String status=s[1];
                                                                    String tsdate=s[2];
                                                                    tf.setTeamid(user);
                                                                                    tf.setHour(dd);
                                                                                    tf.setWork(work);
                                                                                    tf.setStatus(status);
                                                                                    tf.setTsdate(tsdate);
                                                                                    flag=new TimeSheetDAO().AddTimeSheet(tf);
                                                                    }
                                                    }                             
                                    }
                    catch(Exception e)
                                    {e.printStackTrace();}
                                    if(flag)
                                    {
                                                    String user=(String)sess.getAttribute("user");
                                                    System.out.println("user"+user);
                                                    String role=null;
                                                    try {
                                                                    role=new SecurityDAO().getLoginType(user);
                                                                    System.out.println("role"+role);
                                                    } catch (SQLException e) {
                                                    // TODO Auto-generated catch block
                                                    e.printStackTrace();
                                    }
                                    sess.invalidate();
                                    HttpSession session=request.getSession();
                                    session.setAttribute("user",user);
                                    session.setAttribute("role", role);
                                    target="TeamHomePage.jsp";
                    }             
                    else
                                    target="TeamHomePage.jsp";
                    RequestDispatcher rd=request.getRequestDispatcher(target);
                    rd.forward(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }

}

File: TeamRegisterAction.java
package com.live.action;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.live.dao.ProfileDAO;
import com.live.form.RegisterForm;

public class TeamRegisterAction extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public TeamRegisterAction() {
                    super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
                    super.destroy(); // Just puts "destroy" string in log
                    // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    doPost(request,response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     *
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                                    throws ServletException, IOException {

                    boolean flag=false;
                    String target="";
                    RegisterForm rf=new RegisterForm();
                    response.setContentType("text/html");
                    HttpSession sess=request.getSession();
                    if((sess.isNew()))
                    {             
                                    sess=request.getSession();
                    }
//                 if(request.getParameter("add").equalsIgnoreCase("ADD TEAM"))
//                 {
                                    System.out.println("in session");
                                    String bno=request.getParameter("batchno");
                                    System.out.println("insdfdsaf"+bno);
                                    sess.setAttribute("bno",bno);
                                    String year=request.getParameter("year");
                                    sess.setAttribute("year",year);
                                    String loginname=request.getParameter("loginname");
                                    sess.setAttribute("loginname",loginname);
                                    String password=request.getParameter("password");
                                    sess.setAttribute("password",password);
                                    String uname=request.getParameter("uname");
                                    sess.setAttribute("uname",uname);
                                    String email=request.getParameter("email");
                                    sess.setAttribute("email",email);
                                    String prjname=request.getParameter("prjname");
                                    sess.setAttribute("prjname",prjname);
                                    String techused=request.getParameter("techused");
                                    sess.setAttribute("techused",techused);
                                    String secretquestionid=request.getParameter("secretquestionid");
                                    sess.setAttribute("secretquestionid",secretquestionid);
                                    if(request.getParameter("ownsecretquestion")!=null){
                                                    String ownsecretquestion=request.getParameter("ownsecretquestion");
                                                    sess.setAttribute("ownsecretquestion",ownsecretquestion);
                                    }
                                    String secretanswer=request.getParameter("secretanswer");
                                    sess.setAttribute("secretanswer",secretanswer);
                                    String projtype=request.getParameter("projtype");
                                    sess.setAttribute("projtype", projtype);
                                    flag=true;
//                 }
                   
                                    if(flag)
                                                    target="AddTeamMembers.jsp";
                                    else
                                                    target="TeamRegister.jsp";
                                    RequestDispatcher rd=request.getRequestDispatcher(target);
                                    rd.forward(request,response);
                   
    }

   
   
    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
                    // Put your code here
    }

}


***