Web development file
Web development file
)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Index
Experiment:1 2
Experiment : 2 21
Experiment-3 24
Experiment-4 27
Experiment-5 30
Experiment-6 38
Experiment 7 42
Experiment 8 46
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Experiment:1
Aim – Download and Install tools for Web Development Step by Step with Their Screenshots.
The very first step is to download the Oracle Java Development Kit (JDK) from the
Official Oracle Website. For that, Head over to the Official Website. .
Here, you can download zip archive, EXE installer or MSI installer. I recommend you use
EXE installer that updates environment variable automatically, which makes the installation
simple and easy.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
So click the download link next to x64 Installer (1). It will download the EXE installer for
Oracle JDK 21 (file name: jdk-21_windows-x64_bin.exe).
Before opening the setup program, it’s strongly recommended to verify integrity of the
downloaded file by checking its SHA256 checksum value. Open a new Command prompt
window and change the current directory to where the file is downloaded. Type the
following command:
certutil -hashfile jdk-21_windows-x64_bin.exe sha256
Then compare the SHA256 checksum value printed by this command against the value
published on the download page (click link 2 as shown in the above screenshot). If both
values are identical, you can proceed next.
Now click Next to see the below image, Here you have a choice to change the Java
installation directory by clicking on the change… button otherwise simply go with the
default path by clicking the Next > button. I am going here with the default path only.
Once you click the Next button, you will see the start of the installation process as below
image. After successful installation, you close the installation wizard.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Open the system environment variables dialog to do the setup. To open the dialog, you can
type ‘System environment‘ in the Window’s search box as below image and open it.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Once it’s open you can able to see the below dialog box.
Now click on the Environment Variables button > add JAVA_HOME & edit Path as shown
in the below images:-
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Now we should have to add Java Path. If the Path variable is already there then
simply we can click on the Edit… button > then click the New button to add the
path as below image.
Once open the Command Prompt window, type java -version and press Enter key.
Click Next twice to perform the setup with default installation directory
at C:\Program Files\Java\jdk-21. Note that the installer will update the system
environment variable PATH automatically, i.e. putting C:\Program
Files\Common Files\Oracle\Java\javapath as the first entry in the PATH system
environment variable.
Now, open another Command Prompt window and type java -version and javac -
version to verify the installation. It will print the version of Java virtual machine
(java.exe) and Java compiler (javac.exe):
Step1: In the first step, Open your browser and navigate to this
@https://www.eclipse.org/downloads/.
Step 4: Then click on the “Download” button. After clicking on the download button the
.exe file for the eclipse will be downloaded.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Step 5: Now go to File Explorer and click on “Downloads” after that click on
the “eclipse-inst-jre-win64.exe” file for installing Eclipse IDE .
Now, you are ready to make new Java projects using eclipse IDE and the screen will look
like this :-
Step 1: We need to first install the Tomcat 10 zip file from this website. On the website,
select the 64-bit Windows zip (PGP, sha512) in the Core section to start the download
process for the Tomcat zip file.
Step 2: Check If JDK Is Installed. Open Command Prompt and enter the following
commands:- java –version , javac –version.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
If JDK is not installed on your computer, install JDK. In the above picture, we can see JDK
is already installed on our computer.
Step 3: Unzip Tomcat 10 Zip File. Go to the location where you have downloaded the
Tomcat 10 zip file. Right-click on the apache tomcat file place the cursor on 7-Zip and click
on Extract Here to extract the folder.
Step 4: Creating JAVA_HOME Variable:- Click Start then in the search bar, search for
“Edit the system environment variables” and click on it. The following System Properties
box will open. Select Environment Variables in the box.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Step 5: We have to create a JAVA_HOME variable and insert the path of the JDK file
stored in our computer, which will be shown below. So select New from the System
variables in the above picture. A New System Variable box will be opened where we will
have to fill in the Variable name and Variable value.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Step 6: Go to the location where you have stored the contents of the JDK file in My
Computer or PC. Copy the root path of the location of the JDK file as shown below.
Step 7: Paste the JDK path from the above picture into the Variable value field and in the
Variable name field, give the name JAVA_HOME as shown below.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Step 8: Check the Working of Tomcat. Open the extracted apache tomcat file. We will see
all the following files in them. Among them open the batch file named “startup”.
Step 10: Successful Installation of Tomcat. Our next step is to open an internet browser
like Google and type in the address
http://localhost:8080
Then click enter and the following browser will appear suggesting the successful installation
of Apache Tomcat.
Experiment : 2
Aim: Create a Dynamic Web Project and Create a new Html file and write “Hello World”.
The below-given program is the most simple program of Java printing “Hello World” to the
screen. Let us try to understand every bit of code step by step.
Experiment-3
Aim: Divide page in two rows and dividing second row into two columns and also use iframe tag.
Iframe tag used as an inline frame (iframe) is a HTML element that loads another HTML page within the
document. It essentially puts another webpage within the parent page.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Before click
After Click
Result: Successfully divided page into required divisions and used iframes.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Experiment-4
Aim: Installing Struts 2
Software Needed:
1. Java JDK
2. Struts 2 API
3. Apache Tomcat 9
Steps to follow to download struts 2
2. Download struts-2.5.30-all.zip
6. Further Installation is similar to Tomcat version 10.1 that was installed earlier.
Experiment-5
Aim: Creating Struts2 Application in eclipse.
Steps to follow to create struts 2 application:
1. Create a Dynamic Web Project and select the target runtime as Apache Tomcat v9.0, leave the
dynamic web module version as 4.0, and in Web Module setting check the option Generate web.xml
deployment descriptor.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
2. Right-click Java Resources -> New -> Source Folder. In the Project Name select the project created
in step 1 and give the Folder Name as src/main/resources.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
3. Right-click resources folder created in step 2 -> New -> Other -> XML File and assign the name of
commons-fileupload-1.4.jar
commons-io-2.6.jar
commons-lang3-3.8.1.jar
commons-logging-1.2.jar
freemarker-2.3.31.jar
javassist-3.20.0-GA.jar
ognl-3.1.29.jar
struts2-core–2.5.30.jar
log4j-api–2.12.4jar
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
9. Right Click project -> Properties -> Select Deployment Assembly -> Add -> Select Java Build Path
Entries -> Next -> Select Struts2 -> Finish -> Apply -> Apply and Close
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
10. Right Click project -> New -> JSP File, create a file named success.jsp and copy the given code into
it
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
11. Similarly, create a file named error.jsp and copy the given code into it
12. Right Click project -> New -> Class, give the class name as MyAction and click OK
, at the end of the URL include getMessage.action and press Enter key
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Experiment-6
Aim: To install MySQL database.
Follow the following steps to install MySQL database server:
1. Go to https://dev.mysql.com/downloads/file/?id=526408 and No thanks, just start my download.
2. Select the mysql-installer-community-8.0.36.0.msi and hit enter following screen will appear
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
6. Click on next until you come across accounts and roles screen:
7. Enter any password for MySQL server and click next until you come across Apply Configuration.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Experiment 7
Aim: Write a program for Struts and MySQL connectivity.
Tools Used:
1. Eclipse
2. Struts 2.5.33
3. Tomcat Server v9.0
4. MYSQL Database v8.3.0
Step-2: Open Eclipse , create a dynamic web project and configure it with struts2 .
1. Upload all the jar files .
2. Create struts.xml , web.xml , Myaction.java files .
3. Download and upload mysql-connector-j-8.3.0.jar file , used to connect struts2 and MySql database .
MyAction.java:
import com.opensymphony.xwork2.ActionSupport;
import java.sql.*; @SuppressWarnings("serial") public class MyAction
extends ActionSupport {
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration
2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="default" namespace="/" extends="strutsdefault">
<action name="abc" class="MyAction">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>
</action>
</package>
</struts>
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance"
xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
After performing the above steps, we have successfully connected our MySQL database with Struts2
Application.
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Experiment 8
Aim: Write a program for using MySQL database to store data from “FORM” made using JSP.
Tools Used:
1. Eclipse
2. Struts 2.5.33
3. Tomcat Server v9.0
4. MYSQL Database v8.3.0
Code –
register.jsp
success.jsp
error.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>Registration Error</h2>
<h2>Error</h2>
<p>An error occurred: <%= request.getAttribute("errorMessage") %></p>
<p>Please try again later.</p>
<p><a href="register.jsp">Go back to registration page</a></p>
</body>
</html>
register.java
package in.sp.backend;
@WebServlet("/register")
public class Register extends HttpServlet {
private static final String URL = "jdbc:mysql://localhost:3306/register"; private static final String USER =
"root"; private static final String PASSWORD = "root";
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException { response.setContentType("text/html");
PrintWriter out = response.getWriter();
try {
// Load the MySQL JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
// Establish a connection to the database
Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
// Prepare SQL statement for inserting user data
String sql = "INSERT INTO users (username, email, password) VALUES (?, ?, ?)";
PreparedStatement statement = conn.prepareStatement(sql); statement.setString(1,
username); statement.setString(2, email); statement.setString(3, password);
request.setAttribute("errorMessage", e.getMessage());
request.getRequestDispatcher("error.jsp").forward(request, response); }
}
}
VARCHAR(50)
);
College of Technology and Engineering, MPUAT, Udaipur (Raj.)
Name –Raman Raj Singh Class - B. Tech, III Year Branch - AI & DS Semester – VI
Subject – Web Development (AI 367)
Output –