Simple registration example using servlet and JSP



            This example shows how to create a simple Registration page using servlet and JSP to get user information

        Click here for registration form with Mysql database connectivity

JSP code for registration form

<%@ 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>User Data</title>
</head>
<style>
div.ex {
	text-align: right width:300px;
	padding: 10px;
	border: 5px solid grey;
	margin: 0px
}
</style>
<body>
	<h1>Registration Form</h1>
	<div class="ex">
		<form action="RegistrationController" method="post">
			<table style="with: 50%">
				<tr>
					<td>Full Name</td>
					<td><input type="text" name="fullname" /></td>
				</tr>
				<tr>
					<td>Address</td>
					<td><input type="text" name="address" /></td>
				</tr>
				<tr>
					<td>Age</td>
					<td><input type="text" name="age" /></td>
				</tr>
				<tr>
					<td>Qualification</td>
					<td><input type="text" name="qual" /></td>
				</tr>
				<tr>
					<td>Percentage</td>
					<td><input type="text" name="percent" /></td>
				</tr>
				<tr>
					<td>Year Passed</td>
					<td><input type="text" name="yop" /></td>
				</tr>
			</table>
			<input type="submit" value="register" />
		</form>
	</div>
</body>
</html>

web.xml mapping

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>registration</display-name>
<welcome-file-list>
<welcome-file>registration.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>RegistrationController</display-name>
<servlet-name>RegistrationController</servlet-name>
<servlet-class>com.candidjava.RegistrationController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationController</servlet-name>
<url-pattern>/RegistrationController</url-pattern>
</servlet-mapping>
</web-app>

Registration Servlet code

package com.candidjava;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class UserDataServlet
 */
public class RegistrationController extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String name = request.getParameter("fullname");
		String Addr = request.getParameter("address");
		String age = request.getParameter("age");
		String Qual = request.getParameter("qual");
		String Persent = request.getParameter("percent");
		String Year = request.getParameter("yop");
		if(name.isEmpty()||Addr.isEmpty()||age.isEmpty()||Qual.isEmpty()||Persent.isEmpty()||Year.isEmpty())
		{
			RequestDispatcher rd = request.getRequestDispatcher("registration.jsp");
			out.println("<font color=red>Please fill all the fields</font>");
			rd.include(request, response);
		}
		else
		{
			RequestDispatcher rd = request.getRequestDispatcher("home.jsp");
			rd.forward(request, response);
		}
	}

}

Success page (home.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>Display</title>
<style>
table#nat{
	width: 50%;
	background-color: #c48ec5;
}
</style>
</head>
<body>  
<% String name =  request.getParameter("fullname");
	String Addr = request.getParameter("address");
	String age = request.getParameter("age");
	String Qual = request.getParameter("qual");
	String Persent = request.getParameter("percent");
	String Year = request.getParameter("yop"); %>
<table id ="nat">
<tr>
	<td>Full Name</td>
	<td><%= name %></td>
</tr>
<tr>
	<td>Address</td>
	<td><%= Addr %></td>
</tr>
<tr>
	<td>Age</td>
	<td><%= age %></td>
</tr>
<tr>
	<td>Qualification</td>
	<td><%= Qual %></td>
</tr>
<tr>
	<td>Percentage</td>
	<td><%= Persent %></td>
</tr>
<tr>
	<td>Year of Passout</td>
	<td><%= Year %></td>
</tr>
</table>
</body>
</html>

Screenshot

             

            

            

Download

                Registrationexample war

                Registrationexample zip




Related Post

Comments

XenCib
         In this age people share images so many times a day they need a high quality and safe application to do this task. Xender app is one of them. With this app you can transfer your photo everywhere you want, from your Android to pc and vice versa. You may download Xender from https://xender-download.com for free!
ishan
         uyr8
BrjancevWP
         ??иве???в??. Реализ?ем ??л?ги: ?емон? ?иловой ?лек??оники, моде?низа?и? п?ом??ленного обо??довани?, ?емон? ?а??о?н?? п?еоб?азова?елей, ав?ома?иза?и? ?е?нологи?е?ки? п?о?е??ов, ?емон? ????ой??в плавного п??ка, ?емон? п?ом??ленной ?лек??оники, наладка п?ом??ленной ав?ома?ики: ATV61WD75N4, ATS22C25Q, FR-A120E-22K, CIMR-F7A41P51, IMS20018-V5-C24-F1-E4, ATV12H075M2TQ, VFD750VL43A, SMC932500-P, VFD004S21A, M100-01200024A, M400-02400032A, ATV71WD37N4, ATV61EXC2D90N4H, CIMR-VC4A0038BAA-1000, CIMRV7AZ40P20, EI-9011-025H, ATV71WD22N4A24, MP825A6R, CIMR-F7Z40750B, VFD015C43A, CIMR-F7Z44P01B, CIMR-VCBA0010HAA, FR-A220-22K-UL, ATS48D88Y, ATV71E5U30N4, VFD075V43A, QMP350A4R, CIMR-F7C43P71, CIMR MTIII 7.5, 3G3RV-B411K, ATV71EXS5C50Y, M700-09402240A, FR-V240E-37K, M100-03400073A, CSX-110-V4-C1, CIMRE7Z41850A, GP102030, ATV61EXC5C31N4H, M810-03200050A, CIMRV7TC40P47, M200-02400023A, ATV61EXC2D75N4H, CIMRV7SC40P77, CIMRJ7AC44P00, EI-9011-600H, CIMRF7Z40P41B, CIMR-V7SC40P47, MP470A5R, ATV71QC63Y, CIMR-V7AT40P20, EI-9013-1000H, VFD 004, CIMR-VC4A0018BAA-1000, M100-01200017A, C1MR-L7Z4011, CIMR-G7A40550, CIMR-G7C42P21B, CIMR-J7CC40P20, EI-9011-100H, CFW080070TDN1A1Z, CIMR-F7C40550, CIMR-V7TC24P07, MA7200-4015-N1, FR-A240-15K-UL, CIMRE7Z40551A, ATV32HU15M2, ATV61WD30N4U, E1-P7002 075H, FR-Z240-22K-UL, ATV71LD11N4Z, M700-10403200E, CIMRG7C27P51B, ATV71WU15N4, FR-A220-0.4K-UL, SMC940150-P, VFD022V43A, CIMRV7SC41P57, FR-A840-06100, CIMR-V7TC20P77, VFD001L21B, VFD055F43B-G, E2-8300-025H, SJ300-110LFU, CFW100040SAZ, M400-07400660A, ATV212HU30M3X, ATV61EXC5C25Y, ATV61EXC2C31N, IMS20141-V5-C24-F1-E4, CFW-090054TDDBZ, ATV61E5D11N4, CIMRV7AZ25P51, 3G3PV-A4055, L300P-185LFU2, CIMR-G7A47P51, FR-S520E-0.2K, QMP700A4R, ATV71HC31N4D, CIMR-F7C20370, ATV312HU40N4B, и д?. Prom Electric http://prom-electric.ru/articles/1/892/
Ellkeyday
         Dilantin Cialis Apotheke Frankreich cialis for sale Propecia 1mg 20mg
Ellkeyday
         Cialis Kaufen Pillendienst 20 Mg Levitra Paroxetina Receta cialis price Levitra Shipped From Us Levitra Bucodispersable Prospecto
Ellkeyday
         Avis Cialis En Ligne Does Walgreens Sell Cytotec Purchase Alli Online cialis 40 mg Zithromax 500 Mg
mayuri
         i want to upload image aslo so what should i take in successPage(home.jsp) for image.
Ellkeyday
         Viamedic Complaints Azithromycin Part Of Keflex Family Free Shipping Dutasteride Pharmacy prix du viagra 25mg Buy Gsk Propecia buy generic accutane no prescription

©candidjava.com