Spring 2024 - CS311 - 2
Spring 2024 - CS311 - 2
02
Total Marks: 20
Semester: Spring 2024
Topics Covered: 190-210
Introduction to Web Services Development – CS311 Due Date: 24th June, 2024
Instructions:
Please read the following instructions carefully before submitting assignment:
It should be clear that your assignment will not get any credit if:
Objectives:
To understand and get hands on experience of:
HTML
Servlet
Consider the following two files (MyForm.html and MyResults.java). You are required to write
missing code and correct the code in case of error (if any) for MyForm.html which reads any number
to calculate the square and factorial and sends them to MyResults.java Servlet. NowMyResults.java
Servlet will calculate result for the square and factorial of that numbers and display output.
Write the missing code of MyForm.html and MyResults.java (at points mentioned in code below
with … and in red color comments). Exception handling should be done as well wherever
necessary.
MyForm.html
<form action="MyResults" method="post"> // write code here for method type
<!DOCTYPE html>
<html>
<head>
<title>Calculate Square and Factorial</title>
<meta charset=”UTF-8”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
</head>
<body>
<form action="MyResults" method="post">
<label for="num">Enter Number:</label>
<input type="number" id="num" name="num"/><br/>
<input type="submit" value="Result"/>
</form>
</body>
</html>
MyResults.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// write code here to get value of number to calculate square and factorial and display result
int number;
try {
number = Integer.parseInt(numberStr);
}
catch (NumberFormatException e) {
res.setContentType("text/html");
res.getWriter().println(message);
}
}
BEST OF LUCK