Question: Please code and fix this so that the html file and servlet file work together, please it so that they can run together html: Score
Please code and fix this so that the html file and servlet file work together, please it so that they can run together
html:
servlet java file:
import java.io.IOException; import java.io.PrintWriter;
import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
@WebServlet("/hcalcservlet") public class hcalcservlet extends HttpServlet { private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int totalScore = 0;
// Get personal information from request parameters String user = request.getParameter("user"); String phone = request.getParameter("phone"); String email = request.getParameter("email"); String address = request.getParameter("Address");
// Get hobby information from request parameters and calculate score String running = request.getParameter("running"); if (running != null) { totalScore += 10; } String swimming = request.getParameter("swimming"); if (swimming != null) { totalScore += 10; } String cycling = request.getParameter("cycling"); if (cycling != null) { totalScore += 10; } String football = request.getParameter("football"); if (football != null) { totalScore += 10; } String soccer = request.getParameter("soccer"); if (soccer != null) { totalScore += 10; } String rugby = request.getParameter("rugby"); if (rugby != null) { totalScore += 10; } String fitness = request.getParameter("fitness"); if (fitness.equals("low")) { totalScore += 10; } else if (fitness.equals("average")) { totalScore += 20; } else if (fitness.equals("high")) { totalScore += 30; } String pop = request.getParameter("pop"); if (pop != null) { totalScore += 10; } String classical = request.getParameter("classical"); if (classical != null) { totalScore += 10; } String country = request.getParameter("country"); if (country != null) { totalScore += 10; } String reading = request.getParameter("reading"); if (reading.equals("HistoricalFiction")) { totalScore += 10; } else if (reading.equals("HistoricalNonFiction")) { totalScore += 20; } else if (reading.equals("CrimeFiction")) { totalScore += 30; } else if (reading.equals("Romance")) { totalScore += 10; } else if (reading.equals("Comedy")) { totalScore += 50; }
// Create response message String message = user + ", your total score is " + totalScore;
// Set response content type and write message to response response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("
"); out.println("" + message + "
"); out.println("Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
