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



Home Answers Viewqa JDBC register servlet vibhu
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Mumbai
register servlet vibhu
1 Answer(s)      a year and 4 months ago
Posted in : JDBC


how to make register servlet?


Advertisement
View Answers

May 22, 2013 at 11:28 AM


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tcs.ignite.servlets;

import com.tcs.ignite.bean.User;
import com.tcs.ignite.dao.UserDAO;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author ignite234
 */
public class register extends HttpServlet {

    public static Map<String, User> userPerson = new HashMap<String, User>();
    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /*
             * TODO output your page here. You may use following sample code.

            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Register</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet Register at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
            * 
            */
            User newUser = new User();
            newUser.setName(request.getParameter("Uname"));
            newUser.setEmail(request.getParameter("Ename"));
            newUser.setPassword(request.getParameter("Pname"));
            newUser.setGender(request.getParameter("gen"));
             newUser.setHobby(request.getParameter("hob"));
             newUser.setCity(request.getParameter("city"));
            UserDAO userDb = new UserDAO();
            if(userDb.saveDetails(newUser))
            {
                RequestDispatcher requestDispatcher = request.getRequestDispatcher("index1.jsp");
                requestDispatcher.forward(request, response);
            }
            else
            {
                RequestDispatcher requestDispatcher = request.getRequestDispatcher("error.jsp");
                requestDispatcher.forward(request, response);
            }
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}


Related Tutorials/Questions & Answers:
register servlet vibhu
register servlet vibhu  how to make register servlet?   ...;"); out.println("<body>"); out.println("<h1>Servlet Register... register extends HttpServlet { public static Map<String, User> userPerson
login and register - Java Beginners
login and register  pls send me the code for login and register immediately  Hi friend, Please specify the technology you want code for login and register. For example : JSP,Servlet,Struts,JSF etc
Advertisements
java.lang.RuntimeException: Failed to register user. - MobileApplications
java.lang.RuntimeException: Failed to register user.  Hi Mr.Deepak i... this java.lang.RuntimeException: Failed to register user.... /tomcat/logs/localhost.2009-12-21.log SEVERE: Servlet.service() for servlet
How to Register Custom MBeans in Tomcat5.5
How to Register Custom MBeans in Tomcat5.5  How to register custom MBeans in Tomcat5.5 , please provide me an end-to-end example
Session Register
Session Register For session register, you will have to first create an action form in HTML that calls the php session_register code.   In PHP form... (); if($_POST["submit"]){ $email=$_POST["email"]; session_register
How to register for SCJP 6 certification ?
How to register for SCJP 6 certification ?  Hi, I want to take up SCJP 6 certification. Can somebody pl tell me how to register and go ahead
Code to register a new patient in a clinic
Code to register a new patient in a clinic  Hi, How do i write a code that allows a user to enter someone's name and then search for that name from a text file. If the name is not available it opens up a form to register
GUI Cash Register system for saloon
GUI Cash Register system for saloon  Gui java cash register I have to make cash register system for saloon. it will look like this but I dont know how to do it. !alt text Example : if customer come to make a hair cut. I
How can we register the variables into a session?
How can we register the variables into a session?  How can we register the variables into a session
Cash Register System - Java Beginners
Cash Register System  Consider the problem below. A Cash Register System for decision making is needed by the management of a newly opening ABC store. You are been given the task to design a system. The system starts when
how can i make monthly register ?
how can i make monthly register ?  how can i make monthly register ? iam using jdeveloper
Register page using servlets,jsp and java beans
Register page using servlets,jsp and java beans  i want code for register page using jsp,serlets and java beans.iam getting error for my code in java beans pls help me   Hi Friend, Please visit the following links
How to Register Domain Name?
establishments to register a domain name and having your own web presence... offerings to a more wider community of buyers. To register a domain name is just... a domain name? To register a domain name has many significances, most
Product Register System using Java
Product Register System In this section, you will learn how to create product register system. For this, we have categorized the products by code 1 (food), 2...*; class Register{ public String item; public int quantity
Fatal error: Call to undefined function session_register() in .php file
Fatal error: Call to undefined function session_register() in .php file ... is coming: Fatal error: Call to undefined function session_register() in ...php file... the session_register() code from your code and use following code: $_SESSION
write a java program to print marklist of n students. input Register number, name and marks of three subjects.
write a java program to print marklist of "n " students. input Register number, name and marks of three subjects.  write a java program to print marklist of "n " students. input Register number, name and marks of three subjects
How to make a CRUD without using SQL Server? by just using your GUI? (CRUD = Creating, Register, Update, Delete)
How to make a CRUD without using SQL Server? by just using your GUI? (CRUD = Creating, Register, Update, Delete)  well I got a Program that can Register Update and delete a account to SQL Server. from now on we have to make
Servlet
Servlet  What is Servlet
Servlet
Servlet  how to navigate one servlet page to another servlet page
servlet
servlet  is there any way to include pdf's in servlet
servlet
servlet  How many times the servlet is accessed
servlet
servlet  what are the methods and interfaces in the servlet api ?   Servlet Tutorials
Servlet,Jsp
Servlet,Jsp   This is my requirement?I have a login page and register page?If I give the url as http://localhost:8080/Project/Login.jsp ,it should go to login page?.then from login page on click of register button I can register
servlet
servlet  how to interact with a servlet from a swing program
servlet
servlet  what are the all necessary configuration to run a servlet
servlet
servlet  i want to create a login page with servlet using database mysql? only in servlet not in jsp plzz help me out
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
servlet
servlet  I designed 1 html form & a servlet but when I click on form I don't get output of servlet Please help
Advertisements
 

 

 

DMCA.com