This tutorial will teach you how to make Registation form Jsp Servlet Mysql Maven step by step.we have created the file index.jsp.
First Step : Open Eclipse IDE Create a New Project -> File -> New->Dynamic Web Project
After Select Dynamic Web Project you will have a screen like this
Type the Project Name Click Finish. After that select the Project and right click you will have a screen shown below.
Configure->Convert to Maven Project.
After Selected.you will have a screen like this.
Click Finish.After that.
You will add the Mysql Connector here .Enter groupId,artifactid or sha1 prefix or pattern textbox type the Dependency name Mysql Connector. you can get the result on the search result below.
Select the Mysql Connector Click Ok Button.
After that create the index,jsp File.
Paste the Code Inside the index,jsp
<html> <head> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous"> </head> <body bgcolor="#fffff" > <form method="post" action="addServlet"> <table width= 500px cellpadding ="2" cellspacing = "2" align ="center" border ="1" bordercolor ="#FF69B4" bgcolor ="#E6E6FA"> <tr> <td align ="center" colspan = "2"><font color ="#0000F"><h2>Student Information</h2></font></td> </tr> <tr> <td align ="center"><b>Student Name</td> <td><input type="text" size="20" name="sname"></td> </tr> <tr> <td align ="center" valign ="top"><b>Course<b></td> <td><select name="course"> <option value="Vb.net">Vb.net</option> <option value="Enterprise Java">Enterprise Java</option> <option value="Core Java">Core Java</option> </select> </td> </tr> <tr> <td align ="center" valign="top"><b>Address<b></td> <td><input type=text name="address"></textarea> </td> </tr> <tr> <td align ="center"><b>Moblie No<b></td> <td><input type="text" size="20" maxlength="10" name="mno"></td> </tr> <tr> <td align ="center"> </td> <td><input type="submit" value="Register" /></td> </tr> </table> </form> </body> </html>
After that Create the Servlet File which name is addServlet
Paste the Code
import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/addServlet") public class addServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PreparedStatement st1=null; Connection con; PrintWriter out = response.getWriter(); String sname =request.getParameter("sname"); String course =request.getParameter("course"); String addr =request.getParameter("address"); String mobile =request.getParameter("mno"); try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost/lblschool", "root",""); String query ="insert into student(sname,course,address,mno)values(?,?,?,?)"; st1= con.prepareStatement(query); st1.setString(1, sname); st1.setString(2, course); st1.setString(3, addr); st1.setString(4, mobile); int k = st1.executeUpdate(); if(k ==1) { out.println("Thanks for registration ......"); String query2 = "select max(id) from student"; Statement st2 = con.createStatement(); ResultSet rs1 = st2.executeQuery( query2); rs1.next( ); String reg_No = rs1.getString(1); out.println("Your registration id is " + reg_No); } else { out.println("Cant' update"); } } catch(Exception ee) { System.out.println(ee.toString()); } } }
GitHub is a powerful tool used by teams and developers around the globe. This guide is…
It's like having a super-smart buddy that is always there to help you write stories,…
The UK is known for its rich history, diverse culture, and most of all its…
Do you have a plan for your next holiday? Being aware of the Bank Holidays within the…
The world is rapidly changing of software development AI-assisted tools for coding have become the main focus. As…
Google Gemini AI is among the top talked about developments. What exactly is it? What…