C#C
C#2y ago
Rafcord

✅ Method doGet create error 404.

I'm trying to create a servlet, but it doesn't work at all. The first page is displayed, but the response only displays a 404 error.
<!DOCTYPE html>
<html>
    <head>
        <title>MVC Servlet</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h2>Solar System</h2>
        <form action="Result" method="get">
            <p>How many planets you want to enter:<input type=number name=numberOfPlanets ></p>
            <input type="submit" value="Enter" />
        </form>
    </body>
</html>

@WebServlet("/Result")
public class Kontroler extends HttpServlet {

 @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String numberOfNewPlanets = request.getParameter("numberOfPlanets");
        int numberOfPlanets = Integer.parseInt(numberOfNewPlanets);

        PrintWriter out = response.getWriter();
        String htmlRespone = "<html>";
        htmlRespone += "Your numberOfPlanets is: " + numberOfPlanets + "<br/>";      
        htmlRespone += "</html>";
        
        out.println(htmlRespone);
    }
}
Was this page helpful?