1. Write the code using HTML and JSP code to calculate addition , subtraction and division of two numbers with example
arithmetic.html
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Operations</title>
<script type="text/javascript">
function performOperations() {
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var sum = num1 + num2;
var difference = num1 - num2;
document.getElementById("sum").innerHTML = sum;
document.getElementById("difference").innerHTML = difference;
}
</script>
</head>
<body>
<form>
<label for="num1">Number 1:</label>
<input type="text" id="num1" name="num1"><br>
<label for="num2">Number 2:</label>
<input type="text" id="num2" name="num2"><br>
<input type="button" value="Calculate" onclick="performOperations()"><br>
<label for="sum">Sum:</label>
<span id="sum"></span><br>
<label for="difference">Difference:</label>
<span id="difference"></span>
</form>
</body>
</html>
arithmetic.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@ include file="arithmetic.html" %>
</body>
</html>
Write HTML and JSP codes for sending details (name,email,phone,dob,gender) from HTML page and displaying them on a JSP Page.
Studentreg.html
re<!DOCTYPE html>
<html>
<head>
<title>Student Registration Form</title>
</head>
<body>
<h1>Student Registration Form</h1>
<form method="post" action="register.jsp">
<label for="name">Name:</label>
<input type="text" name="name" id="name" required><br>
<label for="email">Email:</label>
<input type="email" name="email" id="email" required><br>
<label for="phone">Phone:</label>
<input type="tel" name="phone" id="phone" required><br>
<label for="dob">Date of Birth:</label>
<input type="date" name="dob" id="dob" required><br>
<label for="gender">Gender:</label>
<input type="radio" name="gender" id="male" value="Male" required>
<label for="male">Male</label>
<input type="radio" name="gender" id="female" value="Female" required>
<label for="female">Female</label><br>
<input type="submit" value="Register">
</form>
</body>
</html>
register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Student Details</title>
</head>
<body>
<h1>Student Details</h1>
<p>Name: <%= request.getParameter("name") %></p>
<p>Email: <%= request.getParameter("email") %></p>
<p>Phone: <%= request.getParameter("phone") %></p>
<p>Date of Birth: <%= request.getParameter("dob") %></p>
<p>Gender: <%= request.getParameter("gender") %></p>
</body>
</html>
No comments:
Post a Comment