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
    }

}


***

 

0 comments:

Post a Comment