HTML Forms using JSP Tags

HTML web page using JSP tags.

How to make Web Page using JSP tags

Steps:

Create three files named as form.html,web.xml and E_register.java.

  1. Define all the form input in form.html.
  2. Write entries in web.xml.
  3. Create a table student_detail in ‘Shivani’ database as follows:
mysql>create table user_details (                     Roll_no varchar(11),                     Name varchar(20),                     marks varchar(30),                     Branch varchar(30),                     Mail varchar(50)             );
  • Write a servlet code in E_Register.java.
  • Accessing a  Database named ‘Shivani’ using Servlet code.

Form.html:

<html>
<head>
<title>Registration Form</title>
</head>
<body bgcolor="lightgrey"  text="black" style="font-size:15pt;font-family:Garamond"><center>
<h2>Registration Form</h2>

<form action="Storejsp.jsp" method="post">
     <table name=tab cellspacing=20pt>
	  <tr>
	    <td >
		Enter your Name:
	    </td>
	    <td >
		<input type="text" placeholder="Name"   size=18 name="nm">
	     </td>
	   </tr>
	  <tr>
	    <td>
		Roll no:
	    </td>
	    <td>
		<input type="text" placeholder="Roll no" name="rn">
	     </td>
	   </tr>
	  <tr>
	    <td>
		Email:
	    </td>
	    <td>
		<input type="text"  Placeholder="Email" name="ml">
	     </td>
	   </tr>
		 <tr>
	    <td>
		Marks:
	    </td>
	    <td>
		<input type="text"  Placeholder="Email" name="mk">
	     </td>
	   </tr>
	   	 <tr>
	    <td>
		Branch:
	    </td>
	    <td>
		<input type="text"  Placeholder="Branch" name="br">
	     </td>
	   </tr>
		<tr>
		<td>
		  <input type="Submit" value="Submit" style="width:70px;height:30px;border-radius:5px" >
		 <a href="student.jsp" >show details</a>
		</td>
		</tr>
</table>
</html>

Storejsp.jsp:

<%@ page language="java" contentType="text/html;" %>
<!DOCTYPE html>
<html>
<head>

<title>Store Data</title>
</head>
<body>
<%@page import="java.sql.*,java.util.*,com.mysql.jdbc.Driver"%>
	<%
String Un=request.getParameter("nm");
String Fn=request.getParameter("rn");
String Ln=request.getParameter("ml");
String Em=request.getParameter("mk");
String Gn=request.getParameter("br");



try
{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Shivani", "Santosh", "8506");
Statement st=conn.createStatement();

int i=st.executeUpdate("insert into student_detail values('"+Fn+"','"+Un+"','"+Em+"', '"+Gn+"','"+Ln+"')");
response.sendRedirect("Success.html");
}
catch(Exception e)
{
System.out.print(e);
}

%>
</body>
</html>

Success.html:

<html> <head>  
<title>Thanks for submission</title> </head>
<body  bgcolor=#2E4053 >
<div style=”background:white;margin-top:10%;left:50%;”>        <h1 align=‘center’>        SuccessFully Registered        </h1> </div> </body> </html>

Student.jsp:

<html> <head>
<meta http-equiv=“Content-Type” content=“text/html; charset=ISO-8859-1”> <title>Student details </title> </head> <body>
<form method=“post”> <table border=“2” style=”margin-left:35%;margin-top:10%;”>
<tr> <td>ROLL NUMBER</td> <td>NAME</td> <td>MARKS</td> <td>BRANCH</td> <td>E-MAIL</td> </tr> <%@page import=“java.sql.*,java.util.*,com.mysql.jdbc.Driver”%>   <% try { Class.forName(“com.mysql.jdbc.Driver”); String url=”jdbc:mysql://localhost/Shivani”;
String username=”Shivani”;
String password=”8506″;
String query=”select * from student_detail”;
Connection conn=DriverManager.getConnection(url,username,password);
Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery(query);
while(rs.next()) { %> <tr> <td><%=rs.getInt(“Roll_no”) %></td> <td><%=rs.getString(“Name”) %></td> <td>
<%=rs.getString(“marks”) %></td> <td>
<%=rs.getString(“Branch”) %></td> <td>
<%=rs.getString(“Mail”) %></td> </tr> <% } %> </table> <% rs.close(); stmt.close(); conn.close();     }
catch(Exception e)     { e.printStackTrace();     } %> </form>
</body> </html>
</html>


Output:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top