0

I have set up a tomcat V8.5 server in Eclipse on OSX. I have setup a default servlet to handle get requests from the following html form. I can startup the server and load index.html, but whenever I click submit on the form I receive a 404 error. This code came from a professor and works on her PC, so I am assuming that I have a setup problem with my server on OSX. Does anyone have any idea where I should look first? My professor isn't willing to help diagnose OSX problems. I am not sure exactly what all information I need to provide, happy to provide additional details to anyone willing to help! Thanks in advance!

Picture of my project structure

<form action="http://localhost:8080/CyberFlix0/CyberFlixServlet"     method="get">
  Film Title: <input type="text" name="film_title"><br>
  <input type="submit" value="Submit">
</form>

my doGet function:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.getWriter().append("Served at: ").append(request.getContextPath());
}

Full Servlet Code:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class CyberFlixServlet
*/
@WebServlet("/CyberFlixServlet")
public class CyberFlixServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public CyberFlixServlet() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.getWriter().append("Served at: ").append(request.getContextPath());
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
}

}
Kevin Gardenhire
  • 626
  • 8
  • 22

3 Answers3

0

Change the value of action tag like this: <form action="/CyberFlixServlet" method="get">

nitind
  • 19,089
  • 4
  • 34
  • 43
0

use action="CyberFlixServlet" as shown in bellow

<form action="CyberFlixServlet"     method="get">
  Film Title: <input type="text" name="film_title"><br>
  <input type="submit" value="Submit">
</form>

Please make sure there no Issue exists in your project, for check any issue open problems view from window -> show view -> problems, if there's any error, fix it

eclipse will reject to compile if there is any problems in your project

Sunil
  • 437
  • 3
  • 11
0

I pulled this answer from another post, but this fixes it.

This a problem with tomcat and the catalina config files:

what you have to do is simply:

right click on the server tomcat in eclipse click on properties click switch location a little server will appear on the left side in the navigation view double click on it after you have launched your server Then select use Tomcat installation and save this will solve that common 404 problem.

Kevin Gardenhire
  • 626
  • 8
  • 22