0% found this document useful (0 votes)
8 views3 pages

User Registration Servlet Implementation

This document contains a Java servlet class called regdata that handles HTTP POST requests. The doPost method connects to a MySQL database, inserts user registration data received in the HTTP request (name, username, password, mobile number) into a login table using a prepared statement, and forwards the request to a JSP page. It catches any exceptions that may occur during the database insertion process.

Uploaded by

Code Bind
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

User Registration Servlet Implementation

This document contains a Java servlet class called regdata that handles HTTP POST requests. The doPost method connects to a MySQL database, inserts user registration data received in the HTTP request (name, username, password, mobile number) into a login table using a prepared statement, and forwards the request to a JSP page. It catches any exceptions that may occur during the database insertion process.

Uploaded by

Code Bind
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

package com.

reg;

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

/**

* Servlet implementation class regdata

*/

@WebServlet("/regdata")

public class regdata extends HttpServlet {

private static final long serialVersionUID = 1L;

/**

* @see HttpServlet#HttpServlet()

*/

public regdata() {

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

[Link]().append("Served at: ").append([Link]());

/**

* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)

*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {

try {

// JDBC driver name and database URL

final String JDBC_DRIVER = "[Link]";

final String DB_URL = "jdbc:mysql://localhost/mydm";

// Database credentials

final String USER = "root";

final String PASS = "root";

[Link]("hi");

Connection conn = null;

PreparedStatement stmt = null;

//STEP 2: Register JDBC driver

[Link](JDBC_DRIVER);

//STEP 3: Open a connection


[Link]("Connecting to a selected database...");

conn = [Link](DB_URL, USER, PASS);

[Link]("Connected database successfully...");

//STEP 4: Execute a query

[Link]("Inserting records into the table...");

stmt = [Link]("insert into login values(?,?,?,?)");

[Link](1, [Link]("n1"));

[Link](2, [Link]("un1"));

[Link](3, [Link]("pass"));

[Link](4,[Link]("mno1"));

[Link]();

[Link]("Inserted records into the table...");

[Link]("[Link]").forward(request, response);

catch(Exception e)

[Link]("wrong");

[Link]();

You might also like