Professional Documents
Culture Documents
Cheat Sheet
Cheat Sheet
Q1 Design a web page that contains two fields and four radio buttons Addition,
Subtraction,Division, Multiplication and Submit Button. Write code to implement calculator using
jsp
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<h2>Calculator</h2>
<form action="calculate.jsp" method="post">
<label for="num1">Number 1:</label>
<input type="text" name="num1" id="num1" required><br><br>
<label>Operation:</label><br>
<input type="radio" name="operation" value="addition" required> Addition<br>
<input type="radio" name="operation" value="subtraction"> Subtraction<br>
<input type="radio" name="operation" value="division"> Division<br>
<input type="radio" name="operation" value="multiplication">
Multiplication<br><br>
Q2 Design a web page that contains two fields and four radio buttons Addition, Subtraction,
Division, Multiplication and Submit Button. Write code to implement calculator using Servlet
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<h1>Calculator</h1>
<form action="calculatorServlet" method="post">
<label for="num1">Number 1:</label>
<input type="text" id="num1" name="num1" required><br><br>
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CalculatorServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int num1 = Integer.parseInt(request.getParameter("num1"));
int num2 = Integer.parseInt(request.getParameter("num2"));
String operation = request.getParameter("operation");
int result = 0;
switch (operation) {
case "addition":
result = num1 + num2;
break;
case "subtraction":
result = num1 - num2;
break;
case "division":
if (num2 != 0) {
result = num1 / num2;
} else {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h3>Error: Division by zero is not allowed.</h3>");
return;
}
break;
case "multiplication":
result = num1 * num2;
break;
}
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h3>Result: " + result + "</h3>");
}
}
Q3 Design a web application using JSP that takes name, user name, password and age from
an HTML page. When submit button is pressed it displays the following message:
i) WelCome <name>...!! You are eligible for UG course (if user name & password matches and
age>18)
ii) Welcome <name>...!! You are not eligible for UG course (if user name & password matches
and age<18)
iii) You are not a registered student here (if user name & password do not matche (In this
application check hardcoded information.)
<!DOCTYPE html>
<html>
<head>
<title>UG Course Application</title>
</head>
<body>
<h1>UG Course Application</h1>
<form action="checkEligibility.jsp" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<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>
<label for="age">Age:</label>
<input type="number" id="age" name="age" required><br><br>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<form action="login" method="post">
<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>
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
*optional code
<?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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>LoginApplication</display-name>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
GROUP A
Q1 Develop JavaScript code with POP-UP boxes and functions for the following problems: a)
Input: Click on Display Date button using onclick() function b) Output: Display date in the
textbox.
<!DOCTYPE html>
<html>
<head>
<title>Display Date Example</title>
<script>
function displayDate() {
// Get the current date
var currentDate = new Date();
Q2 Design an HTML page that contains a selection box with a list of 5 countries. When the user
selects a country, its capital should be printed next in the list. Add CSS to customize the
properties of the font of the capital (color, bold and font size
<!DOCTYPE html>
<html>
<head>
<title>Country Capitals</title>
<style>
#capital {
color: red;
font-weight: bold;
font-size: 20px;
}
</style>
<script>
function showCapital() {
var countrySelect = document.getElementById('countrySelect');
var capitalDisplay = document.getElementById('capital');
Q3 Design the following static web pages required for an online book store web site. HOME
PAGE: The static home page must contain three frames. ii) LOGIN PAGE ii) CATOLOGUE
PAGE: The catalogue page should contain the details of all the books available in the web site
in a table. iv) REGISTRATION PAGE.
<!DOCTYPE html>
<html>
<head>
<title>Online Book Store - Home</title>
</head>
<body>
<!-- Header frame -->
<frame src="header.html" noresize="noresize" frameborder="0">
<!DOCTYPE html>
<html>
<head>
<title>Online Book Store - Login</title>
</head>
<body>
<h1>Login</h1>
<form>
<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>
<!DOCTYPE html>
<html>
<head>
<title>Online Book Store - Catalog</title>
</head>
<body>
<h1>Catalog</h1>
<table>
<tr>
<th>Title</th>
<th>Author</th>
<th>Price</th>
</tr>
<tr>
<td>Book 1</td>
<td>Author 1</td>
<td>$10.00</td>
</tr>
<tr>
<td>Book 2</td>
<td>Author 2</td>
<td>$12.50</td>
</tr>
<!-- Add more rows for other books -->
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Online Book Store - Registration</title>
</head>
<body>
<h1>Registration</h1>
<form>
<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>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
Q4 Design a web page on your own to demonstrate the usage of inline, internal and external
style sheet using CSS.
<!DOCTYPE html>
<html>
<head>
<title>CSS Stylesheet Example</title>
<style>
/* Internal style sheet */
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
h1 {
color: #333333;
text-align: center;
}
p{
color: #666666;
line-height: 1.5;
margin-bottom: 20px;
}
</style>
<link rel="stylesheet" type="text/css" href="external.css">
</head>
<body>
<h1>Web Page Example</h1>
<p>This is an example of a web page.</p>
<div>
<h2 style="color: blue;">Inline Style</h2>
<p style="font-size: 18px;">This paragraph uses inline style.</p>
</div>
<div>
<h2>Internal Style</h2>
<p>This paragraph uses the styles defined in the internal style sheet.</p>
</div>
<div>
<h2>External Style</h2>
<p>This paragraph uses the styles defined in the external style sheet.</p>
</div>
</body>
</html>