C
C#10mo 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);
}
}
<!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);
}
}
10 Replies
Pobiega
Pobiega10mo ago
public class Kontroler extends HttpServlet that aint C# my friend in fact, this... looks like Java?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Pobiega
Pobiega10mo ago
Or python 😄
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Pobiega
Pobiega10mo ago
yeah this is Java for sure just wanted to say that python also uses the @Blarg syntax
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Rafcord
RafcordOP10mo ago
It is java.
Thinker
Thinker10mo ago
$java
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server