Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


meena n
how to create servlet
0 Answer(s)      2 years and 8 months ago
Posted in : Java Interview Questions


package com.controller;

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.beans.SampleBean;
import com.dao.*;
/**
 * Servlet implementation class Controller
 */
public class Controller extends HttpServlet {
    private static final long serialVersionUID = 1L;
    String searchNameGlobal=null;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Controller() {
        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 {
        // TODO Auto-generated method stub

        if(request.getParameter("page").equalsIgnoreCase("create"))
    {
        SampleBean sample=new SampleBean();
        sample.setFname(request.getParameter("fname")); 
        sample.setLname(request.getParameter("lname"));
        sample.setAge(Integer.parseInt(request.getParameter("age")));
        sample.setGender(request.getParameter("gender"));
        sample.setPhone(request.getParameter("phone"));
        DbAccess newAccess=new DbAccess();
        try
        {
            newAccess.createStudent(sample);
        }
        catch(Exception e)
        {
            System.out.println("Error in controller create");
        }

    }
    else if(request.getParameter("page").equalsIgnoreCase("view"))
    {
        SampleBean sampleView=new SampleBean();
        DbAccess dbAccess=new DbAccess();
        try
        {
            String searchName=request.getParameter("fname");

            sampleView=dbAccess.viewStudent(searchName);
            request.setAttribute("result", sampleView);
        }
        catch(Exception e)
        {
            System.out.println("Error in view controller");
        }
        RequestDispatcher rd=request.getRequestDispatcher("/jsp/ViewDetails.jsp");
        rd.forward(request,response);
    }
    else if(request.getParameter("page").equalsIgnoreCase("update"))
    {
        SampleBean sampleView=new SampleBean();
        DbAccess dbAccess=new DbAccess();
        try
        {
            searchNameGlobal=request.getParameter("fname");

            sampleView=dbAccess.viewStudent(searchNameGlobal);
            request.setAttribute("result", sampleView);
        }
        catch(Exception e)
        {
            System.out.println("Error in update controller");
        }
        RequestDispatcher rd=request.getRequestDispatcher("/jsp/UpdateDetails.jsp");
        rd.forward(request,response);
    }
    else if(request.getParameter("page").equalsIgnoreCase("updatedetails"))
    {

        SampleBean sampleUpdate=new SampleBean();
        sampleUpdate.setFname(request.getParameter("fname")); 
        sampleUpdate.setLname(request.getParameter("lname"));
        sampleUpdate.setAge(Integer.parseInt(request.getParameter("age")));
        sampleUpdate.setGender(request.getParameter("gender"));
        sampleUpdate.setPhone(request.getParameter("phone"));
        DbAccess dbAccess=new DbAccess();
        try
        {

            dbAccess.updateStudent(sampleUpdate,searchNameGlobal);
        }
        catch(Exception e)
        {
            System.out.println("Error in update controller");
        }
    }
    else if(request.getParameter("page").equalsIgnoreCase("delete"))
    {
        DbAccess accessObject=new DbAccess();
        try
        {
            String deleteName=request.getParameter("fname");
            accessObject.deleteStudent(deleteName);
        }
        catch(Exception e)
        {
            System.out.println("Error in delete controller");
        }
    }
    }


}
![alt text][1]


  [1]: http://

Advertisement
View Answers

Related Tutorials/Questions & Answers:
how to create servlet
how to create servlet   package com.controller; import... com.beans.SampleBean; import com.dao.*; /** * Servlet implementation class... if(request.getParameter("page").equalsIgnoreCase("create
how to create forum on java subject in jsp/servlet ?
how to create forum on java subject in jsp/servlet ?  hi , i want to implement forum on java subject in jsp/servlet technology .how can i do it,which is the table required for it in mysql? formate like what is java is ? 2Reply
Advertisements
how to create a dynamic website - Servlet Interview Questions
how to create a dynamic website  create a dynamic website of a topic...(); } } } ---------------------  web.xml Servlet and JSP Examples. Servlet and JSP Examples insertDataAction
How to create own help forum - JSP-Servlet
How to create own help forum  Hi All, My client given requirements, they need to create their own help forum, I need to do case study for, how to create any forum. if you have any documentation or technical ideas please
How to create Discussion Forum? - JSP-Servlet
How to create Discussion Forum?  Hi, In my project I want to create Disussion Forum . Pls help me out. hitendra  Hi friend, Please give your requirement for create Disussion Forum. Thanks
How to create discussion forum? - JSP-Servlet
How to create discussion forum?  Hi, In reference to my previous query, I m making a project for a medical person, in that I want to create a discussion forum where if any one is having any queries or to discuss some new cases
how to create bean using jsp and servlet
how to create bean using jsp and servlet  public class SampleBean { private String fname=null; private String lname=null; private int age=0; private String gender=null; private String phone=null; }   Please visit
How to create Discussion Forum? - JSP-Servlet
How to create Discussion Forum?  Hi, Can u tell me what do you mean by requirement regarding discussion forum???? Hitendra  Hi, Which technologies you want to use. Please explain (1.) JSP (2.) Servlets
How create auto number? - JSP-Servlet
How create auto number?  Dear, my friend... I really need your help.... I want to ask you, how to make auto number in mysql database? The format that I want is: ======> 00010809, 00020809, 00030809, etc 0001 = auto
how to create xls file and give download option using jsp/servlet?
how to create xls file and give download option using jsp/servlet?  Hi, how to create file and give download option to user,so that the user can save the file on defined path
How to create file and save it into user defined path using jsp/servlet?
How to create file and save it into user defined path using jsp/servlet?  Hi.. Onclick event I have created one file.When file will create it should asked where to save file(like browse option
How do i start to create Download Manager in Java - JSP-Servlet
How do i start to create Download Manager in Java  Can you tell me from where do i start to develop Download manager in java
how to create notepad in java
how to create notepad in java  how to create notepad in java
how to create frame in swings
how to create frame in swings  how to create frame in swings
How to create arrays in JavaScript?
How to create arrays in JavaScript?  How to create arrays in JavaScript
How to create a confirmation box?
How to create a confirmation box?  How to create a confirmation box
How to create an input box?
How to create an input box?  How to create an input box
how to create session for login
how to create session for login  how to create session for login? how to display uploaded resume and images in the profile
Create XML File using Servlet
Create XML File using Servlet       In this section, you will learn how to create xml... = docBuilder.newDocument(); Step 1: Create a Servlet "XmlServlet.java"
create chart - JSP-Servlet
create chart  Sir, I am using ireport 2.0.2 software for creating .jrxml report. I want to create a chart using ireport software. I m using sql 10g as my database. The table consist of columns like employee_id feature_id
How to create a class in java
How to create a class in java  I am a beginner in programming and tried to learn how to do programming in Java. Friends please explain how can I create a class in Java
How to create form in Swings
How to create form in Swings  How to create registration, login and question form in Java Swing?   Creating different forms in Java Swing - Examples how to create registration form in swing swing login form example
how to create web aplli
how to create web aplli  how to Create a web application using any technology to display 10 most relevant tweets from Twitter in real-time for the keyword "@cldmgc
how to create web aplli
how to create web aplli  how to Create a web application using any technology to display 10 most relevant tweets from Twitter in real-time for the keyword "@cldmgc
How to Create Keyboard in JAVA
How to Create Keyboard in JAVA  please help me to create On-Screen Keyboard with java and please give me an another idia to make it ..............iam waiting for your help ,think u so much
how to create a queue - JMS
how to create a queue  Can u please tell me how to create q queue in JMS and also tell me how to write a program to Send a Static Message for JMS Queue ....please i need it urgently
how to create ipa file
how to create ipa file  Hi, How to .ipa file? Thanks   Hi, Please check the thread Resources have been modified iPhone. Thanks
how to create a table
how to create a table  create table tablename (name varchar(10),name.... Use the following query: create table tablename (name varchar(10),address varchar(10)); For more information, visit the following link: Java Create
how to create uiwebview programmatically
how to create uiwebview programmatically  How to create uiwebview programmatically in iPhone application?   Given is the code that will create the WebView programmatically in iPhone.. CGRect webFrame = CGRectMake(0.0
How To Create a Table.
How To Create a Table.  How To Create a Table?   Hi friends, If you want to create a table, you can run the CREATE TABLE statement..._config.php"; $sql = "CREATE TABLE user_info(" . " id INTEGER NOT NULL" . ", name
How to create charts in Java?
How to create charts in Java?  Is there any example of creating charts and graphs in Java? thanks   Hi, check the tutorial: Chart & Graphs Tutorials in Java Thanks
Advertisements
 

 

 

DMCA.com