0

I'm trying to learn Servlet but whenever I create one I can't run it. Eclipse returns a 404 error. I read a lot of questions about it here on stackoverflow and on other websites, I've literally tried everything..

I copied the Root, manager etc.. folders on the workplace I also created a variable in the user section of my computer called HOME_CATALINA with a value "C:\Program Files\Apache Software Foundation\Tomcat 8.0\libservlet-api.jr;C:\Program Files\Java\jre1.8.0_66\bin;." and a value in the System Section called CLASSPATH with a value of "C:\Program Files\Apache Software Foundation\Tomcat 8.0\libservlet-api.jr;C:\Program Files\Java\jre1.8.0_66\bin;."

enter image description here

If I type on the browser "http://localhost:8080" I can see the TomCat webpage. I don't know what to do anymore. I recorded a video so you'll understand: https://www.youtube.com/watch?v=1Y0q6lm7eBU&feature=youtu.be

This is Serv.java:

package pak;

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;

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

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html");

        PrintWriter prik = response.getWriter();

        prik.println("<html><body>Hello World </body></html>");
    }

    /**
     * @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);
    }

}

This is web.xml: pastebin.com/NfJvz5Vh

What should I do? Help :(

YakovL
  • 7,557
  • 12
  • 62
  • 102
TomCa
  • 11
  • 2
  • Open http://localhost:8080/Serv – Alexey Soshin Aug 28 '16 at 18:01
  • I still have the error – TomCa Aug 28 '16 at 18:13
  • You declare /Serv twice, once within web.xml file, and once in the @WebServlet annotation. Try to leave in web.xml only / – Alexey Soshin Aug 28 '16 at 18:22
  • You incorrectly installed Tomcat as a permanent/automatic windows background service intented for production environments (exe file) instead of as a manually managed development server (zip file). The duplicate shows the correct procedure of integrating Tomcat in Eclipse. After having restarted from scratch the correct way, advance here: http://stackoverflow.com/q/11731377 – BalusC Aug 28 '16 at 19:08
  • Sir,i don't want who you are,but i want to merry you!!! – TomCa Aug 29 '16 at 09:52

0 Answers0