KEMBAR78
Webtech Final | PDF | Computing | Software Engineering
0% found this document useful (0 votes)
40 views26 pages

Webtech Final

Uploaded by

khushipathak993
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)
40 views26 pages

Webtech Final

Uploaded by

khushipathak993
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/ 26

PRACTICAL-1

Aim: Write HTML program for designing your institute website. Display departmental
information of your institute on the website.

Program:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Institute Website</title>

</head>

<body>

<header>

<h1>Welcome to XYZ Institute</h1>

<p>Shaping the future, one student at a time! </p>

</header>

<nav>

<a href="#about">About Us</a>

<a href="#departments">Departments</a>

<a href="#contact">Contact Us</a>

</nav>

<section id="about">

<h2>About Us</h2>

<p>XYZ Institute is a premier educational institution offering quality education in various


fields. We are dedicated to providing students with the tools and knowledge needed for success
in today's competitive world. </p>

</section>
<section id="departments">

<h2>Our Departments</h2>

<div class="department">

<h3>Computer Science Department</h3>

<p>The Computer Science Department focuses on teaching programming, AI, web


development, and cutting-edge technologies. </p>

</div>

<div class="department">

<h3>Electronics and Communication Department</h3>

<p>This department provides hands-on training in embedded systems, robotics, and


wireless communication. </p>

</div>

<div class="department">

<h3>Mechanical Engineering Department</h3>

<p>The Mechanical Engineering Department emphasizes design, manufacturing, and


thermal engineering. </p>

</div>

<div class="department">

<h3>Management Studies</h3>

<p>Our Management Department trains future leaders in business, finance, and


entrepreneurship. </p>

</div>

</section>

<section id="contact">

<h2>Contact Us</h2>

<p>Phone: +1-234-567-8900</p>

</section>
</div>

<footer>

<p>&copy; 2024 XYZ Institute. All rights reserved. </p>

</footer>

</body>

</html>
PRACTICAL-2
Aim: Write an HTML/CSS program to design an entry form of student details.
Program:
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Entry Form</title>
</head>

<body>
<h1>Student Entry Form</h1>
<form action="#" method="post">
<label for="name">Full Name:</label><br>
<input type="text" id="name" name="name" required><br><br>
<label for="rollno">Roll Number:</label><br>
<input type="text" id="rollno" name="rollno" required><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>
<label for="gender">Gender:</label><br>
<select id="gender" name="gender" required>
<option value="">Select</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select><br><br>
<label for="department">Department:</label><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Output:
PRACTICAL-3
Aim: Write programs using Java script for Web Page to display browsers information.
Program:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Browser Information</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
background-color: #f4f4f9;
color: #333;
}
.info-box {
border: 1px solid #ccc;
padding: 10px;
border-radius: 5px;
background-color: #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<h1>Browser Information</h1>
<div class="info-box">
<p><strong>Browser Name:</strong> <span id="browserName"></span></p>
<p><strong>Browser Version:</strong> <span id="browserVersion"></span></p>
<p><strong>Platform:</strong> <span id="platform"></span></p>
<p><strong>Language:</strong> <span id="language"></span></p>
<p><strong>User-Agent:</strong> <span id="userAgent"></span></p>
</div>

<script>
// Retrieve browser information using the navigator object
document.getElementById("browserName").textContent = navigator.appName || "N/A";
document.getElementById("browserVersion").textContent = navigator.appVersion || "N/A";
document.getElementById("platform").textContent = navigator.platform || "N/A";
document.getElementById("language").textContent = navigator.language || "N/A";
document.getElementById("userAgent").textContent = navigator.userAgent || "N/A";
</script>
</body>
</html>
Output:
PRACTICAL-4
Aim: Writing program in XML for creation of DTD, which specifies set of rules.

Program:
XML Document (books.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bookstore SYSTEM "books.dtd">
<bookstore>
<book>
<title>Learning XML</title>
<author>John Doe</author>
<price currency="USD">29.99</price>
</book>
<book>
<title>Mastering JavaScript</title>
<author>Jane Smith</author>
<price currency="EUR">35.50</price>
</book>
</bookstore>
DTD File (books.dtd)
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!ATTLIST price
currency CDATA #REQUIRED>
Output:
PRACTICAL-5
Aim: Program to illustrate JDBC connectivity and maintaining database by sending queries.

Program:
importjava.sql.*;
importjava.util.*;
class Main
{
public static void main(String a[])
{
//Creating the connection
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "system";
String pass = "12345";
//Entering the data
Scanner k = new Scanner(System.in);
System.out.println("enter name");
String name = k.next();
System.out.println("enter roll no");
int roll = k.nextInt();
System.out.println("enter class");
String cls = k.next();

//Inserting data using SQL query


String sql = "insert into student1 values('"+name+"',"+roll+",'"+cls+"')";
Connection con=null;
try
{
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

//Reference to connection interface


con = DriverManager.getConnection(url,user,pass);
Statement st = con.createStatement();
int m = st.executeUpdate(sql);
if (m == 1)
System.out.println("inserted successfully : "+sql);
else
System.out.println("insertion failed");
con.close();
}
catch(Exception ex)
{
System.err.println(ex);
}
}
}
Output:
PRACTICAL-6
Aim: Install APACHE TOMCAT web server. Access the static web pages for login id, using this
server.
Theory:
1. Install Apache Tomcat
Step 1: Download Apache Tomcat
• Visit the official Apache Tomcat website: Apache Tomcat Downloads.
• Download the version suitable for your system (e.g., Tomcat 9 or later).
Step 2: Install Tomcat
• Extract the downloaded ZIP or TAR.GZ file to a preferred location on your computer.
• This extracted folder is your Tomcat home directory.
Step 3: Configure Environment Variables (Optional)
• Set JAVA_HOME to the location of your JDK.
• Add the bin folder of the Tomcat directory to your system PATH for easier access to
commands.
Step 4: Start the Server
• Navigate to the bin folder inside the Tomcat directory.
• Run the startup script:
o On Windows: startup.bat
o On macOS/Linux: ./startup.sh
• Open a browser and visit http://localhost:8080 to verify that Tomcat is running.

Program:
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Page</title>
</head>
<body>
<h1>Login Page</h1>
<form action="welcome.html" method="get">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<button type="submit">Login</button>
</form>
</body>
</html>

welcome.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome</title>
</head>
<body>
<h1>Welcome to the Web Application!</h1>
<p>You have successfully logged in.</p>
</body>
</html>

conf/server.xml
<Connector port="8080" protocol="HTTP/1.1" />
Output:
EXPERIMENT NO-7
Aim: Create a Cookie and add four user ids and passwords to this Cookie.
Program:
<form action="servlet1" method="post">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go"/>
</form>
FirstServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response){
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
Cookie ck=new Cookie("uname",n);//creating cookie object
response.addCookie(ck);//adding cookie in the response
//creating submit button
out.print("<form action='servlet2'>");
out.print("<input type='submit' value='go'>");
out.print("</form>");
out.close();
}catch(Exception e){System.out.println(e);} } }
SecondServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SecondServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response){
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Cookie ck[]=request.getCookies();
out.print("Hello "+ck[0].getValue());
out.close();
}catch(Exception e){System.out.println(e);}
}
}
web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>
</web-app>

Output:
EXPERIMENT NO-8

Aim:. Write a java program/servlet/JSP to connect database and extract data from the tables
and display them.
Program:
Retrieve.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%
String id = request.getParameter("userid");
String driver = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String database = "test";
String userid = "root";
String password = "";
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<!DOCTYPE html>
<html>
<body>
<h1>Retrieve data from database in jsp</h1>
<table border="1">
<tr>
<td>first name</td>
<td>last name</td>
<td>City name</td>
<td>Email</td>
</tr>
<%
try{
connection = DriverManager.getConnection(connectionUrl+database, userid, password);
statement=connection.createStatement();
String sql ="select * from users";
resultSet =statement.executeQuery(sql);
while(resultSet.next()){
%>
<tr>
<td><%=resultSet.getString("first_name") %></td>
<td><%=resultSet.getString("last_name") %></td>
<td><%=resultSet.getString("city_name") %></td>
<td><%=resultSet.getString("email") %></td>
</tr>
<%
}
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
</body>
</html>

Output:
EXPERIMENT NO-9

Aim: Write a JSP which insert the details of the 3 or 4 users who register with the web site by
using registration form.

Program:
Register_1.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>Guru Registration Form</title>
</head>
<body>
<h1>Guru Register Form</h1>
<form action="guru_register" method="post">
<table style="with: 50%">
<tr>
<td>First Name</td>
<td><input type="text" name="first_name" /></td>
</tr>
<tr> </tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="last_name" /></td>
<td>UserName</td>
</td>
</tr>
<tr>
<td><input type="text" name="username" /></td>
<td>Password</td>
<td><input type="password" name="password"
</tr>
<tr>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" /></td>
<td>Contact No</td>
<td><input type="text" name="contact" /></td>
</body>
</html>
Guru_register.java
package demotest;
import java.io.IOException;
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 guru_register
*/
public class guru_register extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");
String username = request.getParameter("username");
String password = request.getParameter("password");
String address = request.getParameter("address");
String contact = request.getParameter("contact");

if(first_name.isEmpty() || last_name.isEmpty() || username.isEmpty() ||


password.isEmpty() || address.isEmpty() || contact.isEmpty())
{
RequestDispatcher req =
request.getRequestDispatcher("register_1.jsp");
req.include(request, response);
}
else
{
RequestDispatcher req =request.getRequestDispatcher("register_2.jsp");
req.forward(request, response);
}
}
}

Output:
EXPERIMENT NO-10

Aim: Design and implement a simple shopping cart example with session tracking API.
Program:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShoppingCartViewerSession extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
// Get the current session object, create one if necessary.
HttpSession session = req.getSession(true);
// Cart items are maintained in the session object.
String[] items = (String[])session.getValue("cart.items");
out.println("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>");
out.println("<BODY><H1>Session Tracking Demo</H1>");
// Print the current cart items.
out.println("You currently have the following items in your cart:<BR>");
if (items == null) {
out.println("<B>None</B>");
}
else {
out.println("<UL>");
for (int i = 0; i < items.length; i++) {
out.println("<LI>" + items[i]);
}
out.println("</UL>");
}
// Ask if they want to add more items or check out.
out.println("<FORM ACTION=\"/servlet/ShoppingCart\" METHOD=POST>");
out.println("Would you like to<BR>");
out.println("<INPUT TYPE=submit VALUE=\" Add More Items \">");
out.println("<INPUT TYPE=submit VALUE=\" Check Out \">");
out.println("</FORM>");
// Offer a help page. Encode it as necessary.
out.println("For help, click <A HREF=\"" +
res.encodeUrl("/servlet/Help?topic=ShoppingCartViewer") + "\">here</A>");
out.println("</BODY></HTML>"); }
}

OUTPUT:
Session Tracker
Session Tracking Demo
currently have the following items in your cart:
APPLE
BANANA
MANGO
Would you like to Add More Items
Check Out

You might also like