This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques and have Mario Casciaro & Luciano Mammino on-line!
See this thread for details.
Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to pick up the servlet in the URL

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, newbie again here.......

Just followed a simple excercise of how to implement a servlet. Up until this point there has been no mention of using a web.xml file!

So far I have compiled a java bit of code into a .class and placed it in my directory webapps/ch01/WEB-INF/classes as advised. The code looks like this:


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ch01_06 extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>");
out.println("A Web Page");
out.println("</TITLE>");
out.println("</HEAD>");
out.println("Hello there!");
out.println("</BODY>");
out.println("</HTML>");
}
}


Now the only instructions it then gives me is to use the url: http://localhost:8080/ch01/servlet/ch01_06

I then get the dreaded message this resource is not available 404 etc etc

As I have no web.xml file within my webapps folder, I am confused as to what I have to do for my servlet to be dispalyed in the browser. The instructions in the book have been quite clear up until now, can someone help?

Thanks

 
Sheriff
Posts: 67592
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your tutorial is either very old, very poor, or both.

  • Servlets must be placed in a package other than the default.
  • The package hierarchy needs to reside at WEB-INF/classes, not WEB-INF.
  • You must declare and map the servelt in the deployment descriptor (web.xml).


  • I'd highly recommend finding a better and more modern tutorial.

     
    Ranch Hand
    Posts: 143
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I can highly recommend the following books which have helped my understanding massively.

    Head First Java
    Head First Java Servlets and JSP
     
    Eat that pie! EAT IT! Now read this tiny ad. READ IT!
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
    reply
      Bookmark Topic Watch Topic
    • New Topic