0

I'm working on an example with Eclipse and Tomcat 9.0, dynamic web module 4.0, without generating web.xml deployment.

The project directory is as follow:

enter image description here

where reverse.java is a servlet that get the input parameter send it back to the output page. For some reason, after I hit the submit button, the "/reverse" servlet cannot be reached and tomcat prompts HTTP Status 404 - Not Found page. What did I do wrong?

After hitting the submit button on inputForm.jsp page, it got the error:

Type Status Report

Message /reverse

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

URL I called on submit when enter input = "abcd": http://localhost:8080/reverse?input=abcd

What did I do wrong? Thanks.

shjnlee
  • 221
  • 2
  • 6
  • 20
  • Show the URL you call on submit. – mentallurg Jan 28 '20 at 23:07
  • URL I called on submit when enter input = "abcd": http://localhost:8080/reverse?input=abcd – shjnlee Jan 28 '20 at 23:09
  • What context root you have set, if any? – mentallurg Jan 28 '20 at 23:19
  • @mentallueg I leave everything as default. – shjnlee Jan 28 '20 at 23:39
  • @BalusC: The question you refer does not answer **this** question. Instead, it contains many different guesses what could be the reason and provides many advices what one should try. One of the multiple guesses suggest to try context root, but this answer has **0 votes**, it means the community finds this answer **not useful**. The most voted answers (currently 115 votes) - yours answer by the way - does **not** answer **this** question. So you are pointing to an answer that is **not** useful for **this** question. That's why it is *not correct* to close this question, it should remain open. – mentallurg Jan 29 '20 at 14:39

1 Answers1

1

If you didn't set set context root explicitly, it is set by default to the same name as your project. If your project name is "bla", then the URL to call the servlet should be following: http://localhost:8080/bla/reverse.

mentallurg
  • 4,967
  • 5
  • 28
  • 36
  • How do I set context root, so the servlet could be just http://localhost:8080/reverse? – shjnlee Jan 28 '20 at 23:40
  • In Eclipse select your project, then menu *Project --> Properties*, in the dialog select *Web Project Settings*, then in the field *Context root* set the value to "/" (slash), it cannot be empty. Then restart your application. – mentallurg Jan 29 '20 at 00:15