Results 1 to 3 of 3
  1. #1
    tanu is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default servlet,connection,bean

    connection dao

    package com.dao;

    import java.sql.Connection;
    import java.sql.DriverManager;

    public class StudentConnectionDAO {
    public static Connection getConnection() {
    String serverName = "";
    String portNumber = "";
    String sid = "";
    String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
    String username = "";
    String password = "";
    Connection conn = null;

    try
    {
    // load the JDBC-ODBC Bridge driver
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn =DriverManager.getConnection( url, username, password );
    } catch (Exception e) {
    e.printStackTrace();
    }
    return conn;
    }
    }



    servlet all

    package com.controller;
    import com.bean.*;
    import com.dao.*;

    import java.io.IOException;
    import java.util.*;


    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletContext;

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

    /**
    * Servlet implementation class StudentViewServ
    */
    public class StudentViewServ extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * @see HttpServlet#HttpServlet()
    */
    public StudentViewServ() {
    super();
    // TODO Auto-generated constructor stub
    }

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    }

    /**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException


    {
    response.setContentType("text/html");

    String action=request.getParameter("page");
    System.out.println("value>>>>>>>>>>>"+action);
    if(action.equals("create"))
    {

    boolean regcomplete=false;
    StudentCreateBean stcrbe = new StudentCreateBean();
    System.out.println("I am @ create servlet>>>>>>>>");
    stcrbe.setId(Integer.parseInt(request.getParameter ("sid")));
    stcrbe.setName(request.getParameter("sname"));
    stcrbe.setAge(Integer.parseInt(request.getParamete r("sage")));
    stcrbe.setMbno(request.getParameter("sphn"));
    stcrbe.setAddr(request.getParameter("saddr"));
    stcrbe.setLoc(request.getParameter("sloc"));
    stcrbe.setCol(request.getParameter("scoll"));
    stcrbe.setYr(request.getParameter("syr"));
    stcrbe.setCom(Integer.parseInt(request.getParamete r("scom")));
    stcrbe.setPwd(request.getParameter("spwd"));

    StudentCreateDAO studao = new StudentCreateDAO();
    System.out.println("I am @ servlet>>>");
    try
    {
    regcomplete=studao.studentcreate(stcrbe);
    }
    catch(Exception e) {
    e.printStackTrace();
    }
    if(regcomplete)
    {
    response.sendRedirect("html/successstu.jsp");
    }
    else
    {
    response.sendRedirect("html/failstu.jsp");
    }


    }

    if( action.equals("updatepg") ||action.equals("deletepg"))
    {
    {

    StudentUpdateBean stupbe = new StudentUpdateBean();
    stupbe.setId(Integer.parseInt(request.getParameter ("sid")));
    response.setContentType("text/html");
    if(action.equals("updatepg"))
    {
    boolean updcomplete=false;
    System.out.println("I am @ update servlet>>>>>>>>1");
    System.out.println(request.getParameter("sid"));

    System.out.println("I am @ update servlet>>>>>>>>2");
    stupbe.setName(request.getParameter("sname"));
    System.out.println("I am @ update servlet>>>>>>>>3");
    stupbe.setAge(Integer.parseInt(request.getParamete r("sage")));
    System.out.println("I am @ update servlet>>>>>>>>4");
    stupbe.setMbno(request.getParameter("sphn"));
    System.out.println("I am @ update servlet>>>>>>>>5");
    stupbe.setAddr(request.getParameter("saddr"));
    System.out.println("I am @ update servlet>>>>>>>>6");
    stupbe.setLoc(request.getParameter("sloc"));
    System.out.println("I am @ update servlet>>>>>>>>7");
    stupbe.setCol(request.getParameter("scoll"));
    System.out.println("I am @ update servlet>>>>>>>>8");
    stupbe.setYr(request.getParameter("syr"));
    System.out.println("I am @ update servlet>>>>>>>>9");
    stupbe.setCom(Integer.parseInt(request.getParamete r("scom")));
    System.out.println("I am @ update servlet>>>>>>>>10");
    System.out.println("I am @ servlet>>>");
    stupbe.setStatus(request.getParameter("sst"));
    StudentUpdateDAO stupdao = new StudentUpdateDAO();
    try
    {
    updcomplete=stupdao.studentupdate(stupbe);
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    if(updcomplete)
    {
    response.sendRedirect("html/successstu.jsp");
    }
    else
    {
    response.sendRedirect("html/failstu.jsp");
    }
    }



    else if(action.equals("deletepg"))
    {
    boolean delcomplete=false;
    System.out.println("I am @ delete servlet>>>>>>>>1");
    System.out.println(request.getParameter("sid"));


    StudentDeleteDAO stdedao = new StudentDeleteDAO();
    try
    {
    delcomplete=stdedao.studentdelete(stupbe);
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    if(delcomplete)
    {
    response.sendRedirect("html/successstu.jsp");
    }
    else
    {
    response.sendRedirect("html/failstu.jsp");
    }


    }
    }
    }

    if( action.equals("login") ||action.equals("view")||action.equals("delete") ||action.equals("update"))
    {
    StudentViewBean stvibe = new StudentViewBean();

    System.out.println("I am @ view servlet>>>>>>>>");
    stvibe.setVid(Integer.parseInt(request.getParamete r("sid")));
    StudentViewDAO stuvidao = new StudentViewDAO();
    System.out.println("I am @ view servlet>>>");
    try
    {
    stvibe=stuvidao.studentview(stvibe);
    System.out.println(stvibe.getVid());
    System.out.println(stvibe.getVname());
    System.out.println(stvibe.getVage());
    System.out.println(stvibe.getVmbno());
    System.out.println(stvibe.getVaddr());
    System.out.println(stvibe.getVloc());
    System.out.println(stvibe.getVcol());
    System.out.println(stvibe.getVyr());
    System.out.println(stvibe.getVcom());
    System.out.println(stvibe.getVstatus());

    ServletContext sc = getServletContext();

    request.setAttribute("id", stvibe.getVid());
    request.setAttribute("name", stvibe.getVname());
    request.setAttribute("age", stvibe.getVage());
    request.setAttribute("mobile", stvibe.getVmbno());
    request.setAttribute("address", stvibe.getVaddr());
    request.setAttribute("location", stvibe.getVloc());
    request.setAttribute("college", stvibe.getVcol());
    request.setAttribute("year", stvibe.getVyr());
    request.setAttribute("amount", stvibe.getVcom());
    request.setAttribute("status", stvibe.getVstatus());

    String dele=stvibe.getVstatus();



    if(action.equals("login"))
    {
    int username=Integer.parseInt(request.getParameter("si d"));
    String password=request.getParameter("password");
    Studentloginbean obj= new Studentloginbean();
    obj.setUsername(username);
    obj.setPassword(password);

    StudentloginDAO object = new StudentloginDAO();
    obj = object.login(obj);
    System.out.println(obj.getUsername());
    System.out.println(obj.getPassword());
    if(obj.isValid())
    {


    HttpSession session = request.getSession(true);
    session.setAttribute("currentSessionUser",obj);
    String validity="valid";
    session.setAttribute("isvalid", validity);
    session.setAttribute("stu", obj);
    response.sendRedirect("html/homestu.jsp");
    }

    else
    {
    int id=obj.getUsername();
    System.out.println(id + obj.getUsername());
    response.sendRedirect("html/loginerror.html"); //error page


    }
    }


    else if (dele.equals("inactive"))
    {
    response.sendRedirect("html/deletedstudent.jsp");
    }
    else if(action.equals("view"))
    {

    //String destination = "/resultservlet";
    System.out.println("i am @ view");
    RequestDispatcher rd = getServletContext().getRequestDispatcher("/html/viewstudent.jsp");
    rd.forward(request, response);


    // RequestDispatcher rd = sc.getRequestDispatcher("/jsp/viewstudent.jsp");
    //rd.forward(request, response);
    }
    else if(action.equals("update"))
    {
    System.out.println("i am @ update");
    RequestDispatcher rd = sc.getRequestDispatcher("/html/updatestudent.jsp");
    rd.forward(request, response);
    }
    else if(action.equals("delete"))
    {
    System.out.println("i am @ delete");
    RequestDispatcher rd = sc.getRequestDispatcher("/html/deletestudent.jsp");
    rd.forward(request, response);
    }



    }

    catch(java.lang.NullPointerException a)
    {
    response.sendRedirect("html/nodatastu.jsp");
    }
    catch(Exception e) {
    e.printStackTrace();
    }


    }

    }
    }



    update bean
    int id;
    String name;
    int age;
    String mbno;
    String addr;
    String loc;
    String col;
    String yr;
    int com;
    String status;


    create bean

    int id;
    String name;
    int age;
    String mbno;
    String addr;
    String loc;
    String col;
    String yr;
    int com;
    String pwd;

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: servlet,connection,bean

    Sod it...yes, I will start reporting threads like these.

  3. #3
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: servlet,connection,bean

    As Tolls implied, that is not how this site works at all. Please see the link in my signature on asking questions the smart way before you post again.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 07:55 AM
  2. how toi make Java Bean DataSource connection in ireport
    By Prashant.surwade in forum Advanced Java
    Replies: 17
    Last Post: 12-18-2009, 07:53 AM
  3. Replies: 1
    Last Post: 08-28-2009, 11:46 AM
  4. Servlet to Servlet connection through URLConnection
    By bsrjavaforum in forum Networking
    Replies: 0
    Last Post: 04-01-2009, 04:12 PM
  5. Replies: 0
    Last Post: 01-27-2008, 08:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •