1

I just started servlet/jsp tutorial from yesterday.

I followed the tutorial, but unlike tutorial my code doesn't work.

my system is MacOS. I am going to explain my issues with attached picture so that you guys can help me to figure the issues out.

Below is my folder structure. I added class file(firstServelt.class -sorry I mistyped) into classes folder which is just simply System.out.println("Hello") in service method.

enter image description here

Then, below is web.xml file. I added servlet and servlet-mapping there.

enter image description here

The thing that is weird for me is that when I run server without adding and , which is default initial web.xml, localhost:8080 gives me tomcat page as below.

enter image description here

However, after servlet and servlet-mapping for firstServelt.class, it gives me 404 NOTFOUND pages for "Localhost:8080" as well as "Localhost:8080/hello".

I am supposed that both "Localhost:8080" and "Localhost:8080/hello" should work. (I know the Localhost:8080/hello will give me blank page by printing "hello" into console. but it just give me non found pages). I am really struggling with finding issues. I want to go step further with my tutorial but due to this issue, I am stuck here.

enter image description here

It would be so thankful if anyone help me to fix the issue!

PS. one more question, I don't know why but whenever I stop my tomcat server from terminal, it doesn't stop as background process. so every single time, when I re-run tomcat server, I have to find $ps -ax |grep tomcat then $kill -9 pID. is there any way that this process can be terminated when I just exit from terminal?

Thank you for reading my dumb questions.

Let me know if you need to know other part of code. !

JUNTAE KIM
  • 115
  • 4
  • I see a few issues. Is `firstServelt` a typo in your configuration, or is that the correct servlet class name? Also, I believe the servlet spec requires that a servlet class be in a distinct *Java package*. That is, you'll need a servlet called `mypackage.firstServlet` (or `mypackage.firstServelt` if you prefer). – Christopher Schultz Nov 21 '19 at 16:23

2 Answers2

0

What was the URL you typed in to get the 404? One thing to make sure of is that you type in http://localhost:8080/hello instead of just localhost:8080/hello. That's because the browsers now default to https.

As for the the other process issue, I suggest you shutdown the process for Tomcat in IntelliJ explicitly, possibly using the tomcat Shutdown operation. If this were Eclipse, it would start it as a debuggable process that you could manage in Eclipse as a server, but I don't know how IJ is doing it. I want to say that base Tomcat starts a batch file which is it's own process, and that begins another Java process which is the Tomcat process.

Woodsman
  • 901
  • 21
  • 61
  • Thank you for your comment. I tried http://localhost:8080 and http://localhost:8080/hello. both dont work too. Thank you for your advice! Since this was initial tutorial, I used vs code for now. – JUNTAE KIM Nov 18 '19 at 03:52
0

Most 404 errors are caused by mistyped class names or mapping names in web.xml or annotation setting.

I think there is a problem with the class name and package name in the servlet configuration for "na"

Make sure that the class name is correct, as well as that the package name is correct.

It would have been better if you showed us the servlet code. Anyway I hope this explanation has helped you solve your problem.

newlec
  • 1