<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
Tool Weight to Hip Ratio Calculator
Tool Weight to Hip Ratio Calculator
<%-- Java (Servlet - CalculatorServlet.java) --%>
<%@ page import="java.io.IOException" %>
<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.annotation.WebServlet" %>
<%@ page import="javax.servlet.http.HttpServlet" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>
<%
// Retrieve tool weight and hip circumference from the form
double toolWeight = Double.parseDouble(request.getParameter("toolWeight"));
double hipCircumference = Double.parseDouble(request.getParameter("hipCircumference"));
// Calculate the tool weight to hip ratio
double ratio = toolWeight / hipCircumference;
// Forward the result to the result.jsp page
request.setAttribute("ratio", ratio);
request.getRequestDispatcher("/result.jsp").forward(request, response);
%>
<%-- Java (Servlet - ResultServlet.java) --%>
<%@ page import="java.io.IOException" %>
<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.annotation.WebServlet" %>
<%@ page import="javax.servlet.http.HttpServlet" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>
<%
// Retrieve the ratio attribute from the request
double ratio = (double) request.getAttribute("ratio");
// Display the result
response.getWriter().println("
Tool Weight to Hip Ratio:
" + ratio + "
");
%>
0 Comments