how to develop web application servlet with mysql

Project 1(web application)

In this topic we have to discuss about web designing.
important software.
  1. Eclipse.(platform)
  2. Apache tomcat 8.5.(server)
  3. MySQL (database)
  4. MySQL connecter
Eclipse:- eclipse provide a good platform to develop a web application, Eclipse provide various version but in this case install Eclipse j2EE, because in this version best for web application development.
Apache tomcat:- when we develop the web application, we need to server for the program. The apache tomcat provide many version (1.0-9.0) and we use 8.5. if you want to use different version you can use.
MySQL:- MySQL is a database that hold the data from web application, in the web application we use to data for new user register and login etc.
MySQL connecter:- it use to connect eclipse to database for data manage.
PAGES
Index.html
Register.jsp
ServletRegister.java(Register.jsp)

Index.html

<html>
<head><title>aspprabhat</title></head>
<body>
<center>
<h1> aspprabhat</h1>
<h2> welcome to index page </h2>
<p>go to <a href src="Register.jsp">REGISTER </a>page </p> 
</center>
</body>
</html>

Register.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>aspprabhat</title>
</head>
<body>
<CENTER>
  IF YOU ARE ALREADY REGISTER GOTO <A HREF="login.jsp">LOGIN PAGE</A> 
<h1> REGISTER FORM </h1>
<FORM  action="ServletRegister" method="POST">
<TABLE BORDER="1" BGCOLOR=" ">
 <TR>
  <TD>USERNAME</TD><TD><INPUT type="text" name="username" placeholder="ENTER HERE"> </TD></TR>
 <TR><TD>PASSWORD</TD> <TD><INPUT type="password" name="password" placeholder="ENTER HERE"> </TD></TR>
<TR><TD>FIRST NAME</TD> <TD><INPUT type="text" name="firstname" placeholder="ENTER HERE">  </TD> </TR>
 <TR> <TD>LAST NAME</TD>  <TD><INPUT type="text" name="lastname" placeholder="ENTER HERE"></TD></TR>
 <TR> <TD>CONTACT NO</TD>  <TD><INPUT type="text" name="contect" placeholder="ENTER HERE"> </TD></TR>
 <TR> <TD>ADDRESS</TD>  <TD><INPUT type="text" name="address" placeholder="ENTER HERE"> </TD> </TR>
</TABLE>
<INPUT type="submit" value="submit"><INPUT type="reset" value="reset">
</FORM>
</CENTER>
</body>
</html>

ServletRegister.java

package com.src;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServletRegister
 */
@WebServlet("/ServletRegister")
public class Part extends HttpServlet {
  private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Part() {
        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
  response.getWriter().append("Served at: ").append(request.getContextPath());
 }
 /**
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  */
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
  PrintWriter out=response.getWriter();
  String username=request.getParameter("username");
  String password=request.getParameter("password");
  String firstname=request.getParameter("firstname");
  String lastname=request.getParameter("lastname");
  String contect=request.getParameter("contect");
  String address =request.getParameter("address");
  
  try{
   Class.forName("com.mysql.jdbc.Driver").newInstance();
  Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/automation","root","1234");
  PreparedStatement ps=con.prepareStatement("INSERT INTO automation.register (username,password,firstname,lastname,contect,address)   VALUES('"+username+"','"+password+"','"+firstname+"','"+lastname+"','"+contect+"','"+address+"');");
  /** 
     ps.setString(1, username);
     ps.setString(2, password);
  ps.setString(3, firstname);
  ps.setString(4, lastname);
  ps.setString(5, contect);
  ps.setString(6, address);
  **/
   int status=ps.executeUpdate();
   
   if(status!=0)
    out.println("successfully register move to next page");
  }catch(Exception e2){
    System.out.println(e2);
  }
  out.close();
   }
}

MySQL

CREATE TABLE aspprabhat (
    RegisterID int(11),
  username varchar(45),
  password varchar(45),
    firstname varchar(45),
    lastname varchar(45),
    contact varchar(45),
    address varchar(75) 
); 

No comments:

INTRODUCTION TO COMPUTER NETWORKS

A Computer network consists of two or more autonomous computers that are linked (connected) together in order to: • Share resources (files...