222SOEIT047 Kumarharsh - Zip
222SOEIT047 Kumarharsh - Zip
3. Implement try-catch blocks to handle potential exceptions that may arise due to
incorrect usage.
1. Create an HTTP Servlet that generates a sizable response (JSP page, HTML content).
2. Measure the response size and performance (time taken to generate and send the
response) with headers set using setIntHeader.
4. Analyze the differences in response size and performance between the two approaches.
1. Setting Integer Header: Demonstrates the usage of setIntHeader to set custom integer
headers.
3. Content-Type Header Test: Tests both correct and incorrect usage of the Content-Type
header.
4. Error Handling: Illustrates error detection and handling by triggering exceptions with
invalid headers.
5. Performance Testing: Measures the time taken to set multiple headers for performance
analysis.
<html>
<head>
<title>Experiment 3</title>
color: #fff;
100vh;
h1 { font-size: 2.5rem;
1s ease-in-out;
} p{ font-size: 1.2rem;
in-out;
flex-direction: column;
align-items: center;
}
button { background-
color: #4CAF50;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.2); transition: transform 0.3s ease,
/* Animations */
@keyframes fadeIn {
from { opacity: 0;
transform: translateY(-20px);
} to {
opacity: 1; transform:
translateY(0);
/* Footer */
footer { position:
absolute; bottom:
10px; font-size:
0.9rem; color:
#ddd;
</style>
</head>
<body>
<div>
<h1>Experiment 3</h1>
</form>
</div>
</body>
</html>
jakarta.servlet.annotation.WebServlet; import
jakarta.servlet.http.HttpServlet; import
jakarta.servlet.http.HttpServletRequest; import
jakarta.servlet.http.HttpServletResponse; import
java.io.IOException;
@WebServlet("/MainServlet")
public MainServlet() {
super();
response.setContentType("text/html");
margin: 0;
padding: 0;
direction: column;
justify-content: center;
align-items: center;
height: 100vh;
color: white;
} h1 { font-size: 3em;
ease-in-out;
} button:hover { transform:
.footer { margin-top:
transform: translateY(0); }
@keyframes buttonPulse {
0% { transform: scale(1); }
</style>
""";
if ("setIntegerHeader".equals(action))
Header</h1>");
else if ("setStringHeader".equals(action))
Header</h1>");
else if ("testContentType".equals(action))
{
// Problem 3: Test Content-Type Header
else if ("handleError".equals(action))
try
response.setHeader(null, "InvalidValue");
catch (IllegalArgumentException e)
response.setContentType("text/html");
else if ("testPerformance".equals(action))
System.currentTimeMillis(); response.setHeader("Custom-Header",
else
// Add footer
provided.</div>"); htmlResponse.append("</body></html>");
response.getWriter().println(htmlResponse.toString());
}
When I tap “Set Integer Header” button it will redirect to http://localhost:8080/Experiment_3/MainServlet?action=setIntegerHeader and show this:
When I tap “Set Integer Header” button it will redirect to http://localhost:8080/Experiment_3/MainServlet?action=setStringHeader and show this:
When I tap “Set Integer Header” button it will redirect to http://localhost:8080/Experiment_3/MainServlet?action=testContentType and show this:
When I tap “Set Integer Header” button it will redirect to http://localhost:8080/Experiment_3/MainServlet?action=handleError and show this:
When I tap “Test Preformance” button it will redirect to http://localhost:8080/Experiment_3/MainServlet?action=testPerformance and show this: