I am trying to make my first java servlet.
Its a simple hello world program. A button is clicked and this takes you to a new page displaying the message hello world.
When i run it i get an error page HTTP 404
The requested resource () is not available.
So i assume there is something wrong with my code.
tom davies wrote:I have my servlet in a package named servlets in netbeans. I wrongly thought i would navigate to it using /servlets/ . .
Right -- the package has nothing to do with the URL mapping.
It has worked now i just have the servlet name.
Warning! This will only work when the web app is the root web app. you should always fetch and include the context path when forming URLs in web pages (such as for images and form actions). For the root web app, the context path just happens to be the empty string. Your app will break if the app is depoyed using a differnt context path.
See the JspFaq for how to fetch the context path in a JSP.
I have also just changed it to out.println("message"); instead of the html
Emitting HTML is fine while you are learning. I just wanted to make sure it did not become a bad habit that you'll need to unlearn later.