
1.reg.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>login</title>
</head>
<body>
<script type="text/javascript">
function validateAndSubmit()
{
var name = document.f1.id.value; //first textbox document.formname.elementname.value
var name1=document.f1.pw.value;
/*if(f1.login[0].checked==false || f1.login[1].checked==false)
{
alert("select the login type");
return false;*/
if(name =="" ||name == null ) {
alert("user id cannot be blank!!" );
return false;
}
else if(name1=="" ||name1==null)
{
alert("enter the password" );
return false;
}
document.f1.action ="Servlet";
document.f1.submit();
}
</script>
<form name="f1" >
<form action="Servlet" method="get">
<center>
<font color="253556">USERNAME</font>
<input type="text" name="id"/>
<font color="253556">PASSWORD</font>
<input type="password" name="pw"/>
</center><br>
<center><b><input type="submit" value="Submit" onclick="javascript:validateAndSubmit();"/></b></center>
<br>
<a href="register.jsp">REGISTER HERE</a>
</form>
</body>
</html>
2,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>
<title>example</title>
<script type="text/javascript">
function validateAndSubmit()
{
var name = document.f1.id.value; //first textbox document.formname.elementname.value
var name1=document.f1.pw.value;
/*if(f1.login[0].checked==false || f1.login[1].checked==false)
{
alert("select the login type");
return false;*/
if(name =="" ||name == null ) {
alert("user id cannot be blank!!" );
return false;
}
else if(name1=="" ||name1==null)
{
alert("enter the password" );
return false;
}
document.f1.action ="Servlet";
document.f1.submit();
}
</script>
<form name="f1" onsubmit="return validateAndSubmit()" action="Regservlet" mehtod ="post">
<center>
<font color="253556">USERNAME</font>
<input type="text" name="id"/>
<font color="253556">PASSWORD</font>
<input type="password" name="pw"/>
</center><br>
<center><b><input type="submit" value="Regsiter" /></b></center>
</form>
</body>
</html>
3.Regservlet.java
package servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class Regservlet
*/
public class Regservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public Regservlet() {
// 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
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
try
{
UserBean user = new UserBean();
user.setUserName(request.getParameter("id"));
user.setPassword(request.getParameter("pw"));
user=UserDAO.regist(user);
if(user.isValid())
{
HttpSession session = request.getSession(true);
session.setAttribute("currentuser", user);
response.sendRedirect("welcome.jsp");
}
else
{
System.out.println("sorry not inserted");
response.sendRedirect("Invalid.jsp");
}
}
catch (Throwable theException)
{
System.out.println(theException);
}
}
}
4.userbean.java
package servlets;
public class UserBean {
private String UserName;
private String Password;
private boolean valid;
public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
this.valid = valid;
}
public String getUserName() {
return UserName;
}
public void setUserName(String userName) {
UserName = userName;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
}
5.userDao.java
package servlets;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public class UserDAO {
static Connection con;
static Statement stmt;
public static UserBean regist(UserBean user) {
// TODO Auto-generated method stub
String username=user.getUserName();
String pass=user.getPassword();
String query="insert into register values('"+username+"','"+pass+"')";
try {
con = ConnectionManager.getConnection();
stmt=con.createStatement();
int rows = stmt.executeUpdate(query);
if(rows!=0)
{
user.setValid(true);
}
else
user.setValid(false);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return user;
}
}
6.connectionmanager.java
package servlets;
import java.sql.*;
public class ConnectionManager {
static Connection con;
static String url;
public static Connection getConnection()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println(" Defing the URL");
String url= "jdbc:oracle:thin:@172.24.137.30:1521:ORA10G";
// assuming "DataSource" is your DataSource name
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try
{
System.out.println(" Defing the username");
String username= "e5";
System.out.println(" Defing the password");
String password= "";
System.out.println(" Defing the connection");
con = DriverManager.getConnection(url,username,password);
System.out.println(" connection done" +con);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
return con;
}
}
Thanks

<%@ 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>login</title>
</head>
<body>
<script type="text/javascript">
function validateAndSubmit()
{
var name = document.f1.id.value; //first textbox document.formname.elementname.value
var name1=document.f1.pw.value;
/*if(f1.login[0].checked==false || f1.login[1].checked==false)
{
alert("select the login type");
return false;*/
if(name =="" ||name == null ) {
alert("user id cannot be blank!!" );
return false;
}
else if(name1=="" ||name1==null)
{
alert("enter the password" );
return false;
}
document.f1.action ="Servlet";
document.f1.submit();
}
</script>
<form name="f1" >
<form action="Servlet" method="get">
<center>
<font color="253556">USERNAME</font>
<input type="text" name="id"/>
<font color="253556">PASSWORD</font>
<input type="password" name="pw"/>
</center><br>
<center><b><input type="submit" value="Submit" onclick="javascript:validateAndSubmit();"/></b></center>
<br>
<a href="register.jsp">REGISTER HERE</a>
</form>
</body>
</html>
2.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>
<title>example</title>
<script type="text/javascript">
function validateAndSubmit()
{
var name = document.f1.id.value; //first textbox document.formname.elementname.value
var name1=document.f1.pw.value;
/*if(f1.login[0].checked==false || f1.login[1].checked==false)
{
alert("select the login type");
return false;*/
if(name =="" ||name == null ) {
alert("user id cannot be blank!!" );
return false;
}
else if(name1=="" ||name1==null)
{
alert("enter the password" );
return false;
}
document.f1.action ="Servlet";
document.f1.submit();
}
</script>
<form name="f1" onsubmit="return validateAndSubmit()" action="Regservlet" mehtod ="post">
<center>
<font color="253556">USERNAME</font>
<input type="text" name="id"/>
<font color="253556">PASSWORD</font>
<input type="password" name="pw"/>
</center><br>
<center><b><input type="submit" value="Regsiter" /></b></center>
</form>
</body>
</html>

Please visit the following links:
http://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.