how to create servlet

how to create servlet

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://
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 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 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 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 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
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
Create XML File using Servlet
Create XML File using Servlet       In this section, you will learn how to create xml... = docBuilder.newDocument(); ADS_TO_REPLACE_2 Step 1: Create a Servlet "
create html of word ,excel,ppt - JSP-Servlet
create html of word ,excel,ppt  Plzz tell me how to create html page of word , excel ,ppt document dynamically using jsp because in my project I have to store uploaded files as html page
How to call servlet in JSP?
How to call servlet in JSP?  How to call servlet in JSP
How to use Servlet and Ajax?
How to use Servlet and Ajax?  How to use Servlet and Ajax
how to run servlet - JSP-Servlet
how to run servlet  pls give me comlete procedure to run the servlet on apache-tomcat 6.0.16 how can i set my classpath, java_home etc. also where i have to save my servlet program and how it compile and then run on web browser
How to create an input box?
How to create an input box?  How to create an input box
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 frame in swings
how to create frame in swings  how to create frame in swings
how to create notepad in java
how to create notepad in java  how to create notepad in java
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
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
A simple example of log4j for Servlet
A simple example of log4j for Servlet       This Example shows you how to create a log in a Servlet. Description of the code: Logger.getLogger(): Logger class is used
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 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 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 rdd in pyspark
how to create rdd in pyspark  Hi, I am have to create an RDD from a String in PySpark. How to do this? How to create rdd in pyspark?   Hi, Its easy you can use the following code example: data = sc.parallelize(list
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
how to create array in r
how to create array in r  Hi, In R Programming how array is created? how to create array in r? Explain me the process of array creation using.... You can create an array with the help of array keyword. Following is an example
How to create options in HTML
How to create options in HTML  How to create options in HTML? Please guide me.   Create options in HTML Code <tr> <td width="30" valign="middle">Gender:</td> <td><select
How to create variable in TensorFlow?
How to create variable in TensorFlow?  Hi, How to create variable... variable, you have to create the TensorFlow variable to use it with TensorFlow graph. Then tf.variable() method is used to create variable in TensorFlow
how to create array in python
how to create array in python  Hi, how to create array in python? I want to create an array in Python and add some values to it. Thanks   Hi, You can create a new array with the code myArray = [] and after
how to create vector in r
how to create vector in r  Hi, What is vector in R programming and how to create vector in r? Provide me some of the example code. Thanks   Hi, Vector in R is created using the key c(). Vector contains data of only
how to create interfaces in java
how to create interfaces in java  HI, Here is my code public interface validateInfo { public void validate(String empcode, String password); } class updateInfo implements validateInfo { public void update() { //code
how to create dao
how to create dao   code1: package com.dao; import java.sql.*; import com.beans.*; public class DbAccess { public void createStudent(SampleBean...) { System.out.println("Error in create access"); } } public SampleBean
How to create a jar file
How to create a jar file  Hello!!!! I have a project which has a multiple classes with database connection(MS-Access) & now i want to make a single executable jar of it... so pls tell me how it will b possible for me
how to create using jsp
how to create using jsp  code 1: <%@ page language="java...; <title>Create New Student</title> </head> <body> <form name="create" method="post" action="<
how to create a xml page
how to create a xml page  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <
How map the first_servlet to second_servlet - JSP-Servlet
How map the first_servlet to second_servlet  Hello, I have two questions. 1.How I want map the second_servlet by first_servlet. My Html page map... have a function which define in second_servlet. How that fuction which define
how to create SOAP based web service in java?
how to create SOAP based web service in java?  Hi, I want to create sample SOAP web-service based application using jsp/servlet. Please help me
How to find a servlet object by name?
How to find a servlet object by name?  How can we locate a servlet object in the code by it's object name?   A. In web.xml you map servlet and define url pattern. Now this url-pattern is used for calling servlet. <

Ads