0% found this document useful (0 votes)
19 views

Web Technology (Final File)

The document describes how to create a Java applet that functions as a color mixer palette. It creates sliders and labels to control the red, green, and blue values and displays the mixed color in a panel. Adjusting the sliders updates the color in real-time.

Uploaded by

aviral17850
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Web Technology (Final File)

The document describes how to create a Java applet that functions as a color mixer palette. It creates sliders and labels to control the red, green, and blue values and displays the mixed color in a panel. Adjusting the sliders updates the color in real-time.

Uploaded by

aviral17850
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Lab No:-

Objective: Write a Java applet to display the Application Program screen i.e. Colour mixer palletCode:-
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class ColorMixer extends Applet implements AdjustmentListener {


Scrollbar redSlider, greenSlider, blueSlider;
Label redLabel, greenLabel, blueLabel;
Panel colorPanel;

public void init() {


setLayout(new BorderLayout());

// Create sliders
redSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
greenSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
blueSlider = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);

// Add listeners
redSlider.addAdjustmentListener(this);
greenSlider.addAdjustmentListener(this);
blueSlider.addAdjustmentListener(this);

// Create labels
redLabel = new Label("Red: 0");
greenLabel = new Label("Green: 0");
blueLabel = new Label("Blue: 0");

// Create panel for sliders and labels


Panel controlPanel = new Panel();
controlPanel.setLayout(new GridLayout(3,2));
controlPanel.add(redLabel);
controlPanel.add(redSlider);
controlPanel.add(greenLabel);
controlPanel.add(greenSlider);
controlPanel.add(blueLabel);
controlPanel.add(blueSlider);

// Create panel for displaying color


colorPanel = new Panel();
colorPanel.setBackground(Color.black);

// Add panels to applet


add(controlPanel, BorderLayout.NORTH);
add(colorPanel, BorderLayout.CENTER);
}

public void adjustmentValueChanged(AdjustmentEvent e) {


int redValue = redSlider.getValue();
int greenValue = greenSlider.getValue();
int blueValue = blueSlider.getValue();
redLabel.setText("Red: " + redValue);
greenLabel.setText("Green: " + greenValue);
blueLabel.setText("Blue: " + blueValue);

colorPanel.setBackground(new Color(redValue, greenValue, blueValue));


}
}
Lab No:-
Objective: Write a program using TCP/IP socket between client andserver and perform two-way
communication
Code:-
Server.java
import java.net.*;
import java.io.*;
public class Server {
public static void main(String[] args) {
try {
// Create server socket
ServerSocket serverSocket = new ServerSocket(5000);
System.out.println("Server started...");

// Accept client connection


Socket clientSocket = serverSocket.accept();
System.out.println("Client connected...");

// Create input and output streams


InputStream inputStream = clientSocket.getInputStream();
OutputStream outputStream = clientSocket.getOutputStream();

// Create input and output readers


BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream));
PrintWriter outputWriter = new PrintWriter(outputStream, true);

// Read and write data


String inputLine, outputLine;
while ((inputLine = inputReader.readLine()) != null) {
System.out.println("Client: " + inputLine);
outputLine = "Server received: " + inputLine;
outputWriter.println(outputLine);
if (inputLine.equals("Bye")) {
break;
}
}
// Close everything
inputReader.close();
outputWriter.close();
clientSocket.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Client.java
import java.net.*;
import java.io.*;
public class Client {
public static void main(String[] args) {
try {
// Create client socket
Socket clientSocket = new Socket("localhost", 5000);
System.out.println("Connected to server...");
// Create input and output streams
InputStream inputStream = clientSocket.getInputStream();
OutputStream outputStream = clientSocket.getOutputStream();
// Create input and output readers
BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream));
PrintWriter outputWriter = new PrintWriter(outputStream, true);
// Read and write data
BufferedReader userInputReader = new BufferedReader(new InputStreamReader(System.in));
String userInput, serverResponse;
while ((userInput = userInputReader.readLine()) != null) {
outputWriter.println(userInput);
if ((serverResponse = inputReader.readLine()) != null) {
System.out.println("Server: " + serverResponse);
}
if (userInput.equals("Bye")) {
break;
}
}
// Close everything
userInputReader.close();
inputReader.close();
outputWriter.close();
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Output:-
Lab No:
Objective: Write a program to illustrate JDBC connectivity and perform CRUD operation on a
table student/employee (at least 5 attributes).

Code:

package webtech;
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.DBConversion;

public class Jdbc {


static boolean db_created=false;
public static void main(String args[])
{ Connection con;
Statement state;
ResultSet rs;
int no;
int sal;
String name;
int ch;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver Loaded");

con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","DIVYA","divya");
do
{ System.out.println("\n");
System.out.println("Menu:");
System.out.println("1.Create table");
System.out.println("2.Insert Record into the Table");
System.out.println("3.Update The Existing Record.");
System.out.println("4.Display all the Records from the Table");
System.out.println("5.Delete");
System.out.println("6.Exit");
System.out.println("Enter your choice: ");

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


ch=Integer.parseInt(br.readLine());

String sql;

switch(ch)
{ case 1:
Statement stmt=con.createStatement();
String ct="create table employee(emp_id number(5),emp_name varchar2(30),emp_sal
number(8,2))";
boolean b=stmt.execute(ct);
if(b==false) System.out.println("table not created");
else {db_created=true;}
stmt.close();
break;
case 2:
if(db_created==true){
state=con.createStatement();
int i,n;
System.out.println("enter the no of values you want to insert");
n=Integer.parseInt(br.readLine());
for(i=0;i<n;i++)
{
System.out.println("Enter Employee Number: ");
no=Integer.parseInt(br.readLine());
System.out.println("Enter Employee Name: ");
name=br.readLine();
System.out.println("Enter Employee Salary: ");
sal=Integer.parseInt(br.readLine());
sql="insert into employee values(?,?,?)";
PreparedStatement p=con.prepareStatement(sql);
p.setInt(1,no);
p.setString(2,name);
p.setInt(3,sal);
p.executeUpdate();
System.out.println("Record Added");
p.close();
}}
else
System.out.println("create table first");
break;

case 3:
if(db_created==true){
state=con.createStatement();
System.out.println("Enter Employee Number for the record you wish to Update: ");
no = Integer.parseInt(br.readLine());
System.out.println("Enter new Name: ");
name = br.readLine();
System.out.println("Enter new Salary: ");
sal = Integer.parseInt(br.readLine());
sql="update employee set Name=?, Salary=? where Code=?";
PreparedStatement p=con.prepareStatement(sql);
p.setString(1,name);
p.setInt(2,sal);
p.setInt(3,no);
p.executeUpdate();
System.out.println("Record Updated");
p.close(); }
else
System.out.println("create table first");
break;

case 4:
if(db_created==true){
state=con.createStatement();
sql="select * from employee";
rs=state.executeQuery(sql);
while(rs.next())
{
System.out.println("\n");
System.out.print("\t" +rs.getInt(1));
System.out.print("\t" +rs.getString(2));
System.out.print("\t" +rs.getInt(3));
} }
else
System.out.println("create table first");
break;

case 5:
if(db_created==true){
state=con.createStatement();
sql="delete from employee where emp_id='1'";
rs=state.executeQuery(sql);
state.close();
}
else
System.out.println("create table first");
break;
case 6:
System.exit(1);
break;
default:
System.out.println("Invalid Choice");
break;
}
}while(ch!=6);
con.close();
}catch(Exception e)
{
System.out.println(e);
}

} }
Output:
Lab No:
Objective: Write a program to illustrate Batch Transaction with prepared statements.

Code:

BatchUpdateDemo_Connection.java
package webtech;
import java.sql.*;
public class BatchUpdateDemo_Connection {
public static Connection getOracleConnection()throws Exception{
String driver="oracle.jdbc.driver.OracleDriver";
String URL="jdbc:oracle:thin:@localhost:1521:xe";
String Username="DIVYA";
String password="divya";
Class.forName(driver);
return DriverManager.getConnection(URL,Username,password); } }

BatchUpdate.java
package webtech;
import java.sql.*;
public class BatchUpdate {
static Savepoint sp1;
public static void main(String args[]) throws Exception
{ Connection con=BatchUpdateDemo_Connection.getOracleConnection();
Statement stmt=null;
try{ con.setAutoCommit(false);
stmt=con.createStatement();
stmt.addBatch("delete from emplo");
stmt.addBatch("insert into emplo values(104,'ABC',5694)");
stmt.addBatch("insert into emplo values(105,'DEF',6694)");
int[] uc=stmt.executeBatch();
sp1 = con.setSavepoint("spv1");
stmt.addBatch("insert into emplo values(106,'GHI',7694)");
stmt.addBatch("insert into emplo2 values(107,'JKl',8694)");
int[] uc1=stmt.executeBatch();
System.out.println(". .."+uc.length);
for(int i=0;i<uc.length;i++)
{ System.out.println(uc[i]); }
con.commit(); }
catch(BatchUpdateException e)
{ System.out.println(e);
int[] abc=e.getUpdateCounts();
System.out.println(". .."+abc.length);
for(int i=0;i<abc.length;i++)
{ System.out.println(abc[i]); }
con.rollback(sp1);
con.commit(); } } }
Output:
Lab No:-
Objective: Install a database (Mysql or Oracle). Create a table which should contain at least
the following fields: name, password, email-id, phone number Write a java program/servlet/JSP
to connect to that database and extract data from the tables and display them. Insert the
details of the users who register with the web site, whenever a new user clicks the submit
button in the registration page.

Code:

 index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1><a href="RegisterForm.html">Register new user</a><br>
<a href="Display.jsp">Display existing users</a></h1>

</body>
</html>

 RegisterForm.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head> <body>
<form action="Register.jsp" method="post">
<table>
<tr> <td>Name:</td>
<td><input type="text" name="name"></td> </tr>
<tr> <td>Password:</td>
<td><input type="text" name="password"></td> </tr>
<tr> <td>Email:</td>
<td><input type="email" name="email"></td> </tr>
<tr> <td>Phone Number:</td>
<td><input type="number" name="phone"></td> </tr>
<tr> <td></td>
<td><input type="submit" value="Register"></td> </tr>
</table>
</form>
</body> </html>
 Register.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.Statement" %>
<%@ page import="connection.Connect" %>
<!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>Insert title here</title>
</head>
<body>
<% String name = request.getParameter("name");
String password = request.getParameter("password");
String email = request.getParameter("email");
String phone = request.getParameter("phone");
try {
Statement stmt = Connect.conn().createStatement();
String query = "insert into users1
values('"+name+"','"+password+"','"+email+"',"+phone+")";
stmt.executeQuery(query);
Connect.conn().close();
stmt.close();
out.println("Registration Successfull"); }
catch(Exception e) {
out.println("Registration Unsuccessfull!");
System.out.println(e); }
finally {
out.println("<br><a href='index.html'>Go to home page</a>"); } %>
</body>
</html>

 Display.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%@ page import="connection.Connect" %>
<!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>Insert title here</title>
</head>
<body>
<% try{
Statement stmt = Connect.conn().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from users1");
if(!rs.next()){ out.println("No users registered!"); }
else{
%>
<h1>Users are:</h1><br>
<table border="1">
<thead>
<tr>
<td>Name</td>
<td>Password</td>
<td>Email</td>
<td>Phone</td>
</tr>
</thead>
<tbody>
<%
rs.previous();
while (rs.next()) {

String name = rs.getString(1);


String password = rs.getString(2);
String email = rs.getString(3);
int phone = rs.getInt(4);%>

<tr>
<td><%= name %></td>
<td><%= password %></td>
<td><%= email %></td>
<td><%= phone %></td>
</tr>
<%}}%>
</tbody>
</table>
<% }

catch(Exception e) {
System.out.println(e);
}
finally {
out.println("<br><a href='index.html'>Go to home page</a>");
}
%>
</body></html>

 Connect.java

package connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Connect {


public static Connection conn() throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","akku1","akku1");
return conn;
}
}

Output:
Lab No:
Objective: To Develop a student Mark sheet by using Servlet and HTML with database Oracle.

Code:

Creating Database RESULT:

CREATE TABLE "RESULT"


( "ROLLNO" NUMBER,
"NAME" VARCHAR2(40),
"RESULT" VARCHAR2(40),
"GRADE" VARCHAR2(40),
CONSTRAINT "RESULT_PK" PRIMARY KEY ("ROLLNO") ENABLE
)
/

index.html
<html>
<body>
<form action="servlet/Search">
Enter your Rollno:<input type="text" name="roll"/><br/>

<input type="submit" value="search"/>


</form>
</body>
</html>

Search.java

import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;

public class Search extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

String rollno=request.getParameter("roll");
int roll=Integer.valueOf(rollno);
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","oracle");

PreparedStatement ps=con.prepareStatement("select * from result where rollno=?");


ps.setInt(1,roll);

out.print("<table width=50% border=1>");


out.print("<caption>Result:</caption>");

ResultSet rs=ps.executeQuery();

/* Printing column names */


ResultSetMetaData rsmd=rs.getMetaData();
int total=rsmd.getColumnCount();
out.print("<tr>");
for(int i=1;i<=total;i++)
{
out.print("<th>"+rsmd.getColumnName(i)+"</th>");
}

out.print("</tr>");

/* Printing result */

while(rs.next())
{
out.print("<tr><td>"+rs.getInt(1)+"</td><td>"+rs.getString(2)+"
</td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4)+"</td></tr>");

}
out.print("</table>");
}catch (Exception e2) {e2.printStackTrace();}
finally{out.close();}

}
}

web.xml
<web-app>

<servlet>
<servlet-name>Search</servlet-name>
<servlet-class>Search</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Search</servlet-name>
<url-pattern>/servlet/Search</url-pattern>
</servlet-mapping>

</web-app>

Output:
Lab No:
Objective: Design and implement a simple servlet for an entry form of student details and
send it to store at database server like SQL, Oracle or MS Access.

Code:
Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="./register" method="post">
<table>
<tr> <td>Roll Number:</td>
<td><input type="number" name="roll"></td>
</tr>
<tr> <td>student name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr> <td>Course:</td>
<td><input type="text" name="course"></td>
</tr>
<tr> <td>branch:</td>
<td><input type="text" name="branch"></td>
</tr>
<tr> <td></td>
<td><input type="submit" value="add"></td>
</tr>
</table>
</form>
</body>
</html>

Connect.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Connect {


public static Connection conn() throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","akku1","akku1");
return conn;
}
}

AddInDatabase.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// Servlet implementation class AddInDatabase

public class AddInDatabase extends HttpServlet {


private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
String roll = request.getParameter("roll");
String name = request.getParameter("name");
String course = request.getParameter("course");
String branch = request.getParameter("branch");
try {
Statement stmt = Connect.conn().createStatement();
String query = "insert into student values("+roll+",'"+name+"','"+course+"','"+branch+"')";
stmt.executeQuery(query);
Connect.conn().close();
stmt.close();
out.println("Registration Successfull"); }
catch(java.sql.SQLIntegrityConstraintViolationException e) {
out.println("Error resgistering this student. A student with same roll number exists!");
}
catch(Exception e) {out.println("Registration Unsuccessfull!");
System.out.println(e); }
finally { out.println("<br><a href='index.html'>Go to home
page</a>");
} } }

web.xml

<?xml version="1.0" encoding="UTF-8"?>


<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-
app_2_4.xsd">
<display-name>Servlet Store student details in database</display-name>
<servlet>
<description>
</description>
<display-name>AddInDatabase</display-name>
<servlet-name>AddInDatabase</servlet-name>
<servlet-class>AddInDatabase</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AddInDatabase</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

Output:
Lab No:
Objective: Write a JSP which insert the details of the 3 or 4 users who register with the web
site by using registration form.
Authenticate the user when he submits the login form using the user name and password from
the database

Code:

Connect.java

package connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Connect {


public static Connection conn() throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","akku1","akku1");
return conn; }
}

Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Login Page</h1>
<form action="Login.jsp" method="get"><br>
<table>
<tr> <td>Username</td>
<td><input type="text" name="uname"></td> </tr>
<tr> <td>Password</td>
<td><input type="text" name="upass"></td> </tr>
<tr> <td></td>
<td><input type="submit" value="Login"></td> </tr>
<tr> <td></td>
<td><center><a href="RegisterForm.html">
New user? Register here.</a></center></td> </tr>
</table>
</form>
</body>
</html>
RegisterForm.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Registration Page</h1>
<form action="Register.jsp" method="post"><br>
<table>
<tr> <td>Name</td>
<td><input type="text" name="name"></td> </tr>
<tr> <td>Username</td>
<td><input type="text" name="uname"></td> </tr>
<tr> <td>Password</td>
<td><input type="text" name="upass"></td> </tr>
<tr> <td>Email</td>
<td><input type="text" name="email"></td> </tr>
<tr> <td>Phone Number</td>
<td><input type="number" name="phone"></td></tr>
<tr> <td></td>
<td><input type="submit" value="Register here"></td> </tr>
</table>
</form>
<a href="index.html">Go back to home page</a>
</body>
</html>

Login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%@ page import="connection.Connect" %>
<!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>Insert title here</title>
</head>
<body>
<%
try{boolean exist=false;
Statement stmt = Connect.conn().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from users");
if(!rs.next()){
%>
<h1>No users registered! Register first.</h1>
<%
}
else{

rs.previous();
String uname = request.getParameter("uname");
String password = request.getParameter("upass");
while (rs.next()) {
String name = rs.getString(2);
String pass = rs.getString(3);
if(uname.equals(name)&&password.equals(pass)) {
exist=true;
break; }}
if(exist){ %>
<h1>You have successfully logged in <%= rs.getString(1) %></h1>
<br>
<strong>Your username is <%= rs.getString(2)%><br>
Your email is <%= rs.getString(4)%><br>
Your phone number is <%= rs.getInt(5)%></strong>
<% }
else{
%>
<h1>Wrong username or password!</h1>
<%
}}}

catch(Exception e) {
System.out.println(e);
}
finally {
out.println("<br><a href='index.html'>Go to home page</a>");}%>
</body>
</html>

Register.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.Statement" %>
<%@ page import="connection.Connect" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<%
String name = request.getParameter("name");
String uname = request.getParameter("uname");
String password = request.getParameter("upass");
String email = request.getParameter("email");
String phone = request.getParameter("phone");
try {
Statement stmt = Connect.conn().createStatement();
String query = "insert into users
values('"+name+"','"+uname+"','"+password+"','"+email+"',"+phone+")";
stmt.executeQuery(query);
Connect.conn().close();
stmt.close();
out.println("Registration Successfull");
}catch(java.sql.SQLIntegrityConstraintViolationException e) {
out.println("Error resgistering this user. A student with same username exists!");
}
catch(Exception e) {
out.println("Registration Unsuccessfull!");
System.out.println(e);
}
finally {
out.println("<br><a href='index.html'>Go to home page</a>");
} %>
</body>
</html>

Code:

You might also like