Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Head First Java Chpt. 18. A very simple Servlet

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading the Head First Java 2nd edition, and I am almost done. I am on Chapter 18 working on the very simple servlet which says you need to download the servlets.jar to make it work. I have downloaded the JEE stuff and can still not get it to work. I am wondering what I need to do to get the servlets.jar, and make this servlet work. I am very new to this and very confused. Thanks
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you using for a servlet container? Tomcat? If so, the servlet-api.jsr is part of the download.
 
Keano Denton
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet container? Please excuse the ignorance, but I'm confused. Do I just download Tomcat and install it? I'm sorry for the greenhorn questions
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'Apache Tomcat' is a Servlet container; there are several if not many others. If you have decided to use Tomcat then you need to install it. Once installed it will create a 'lib' directory which contains a jar file "servlet-api.jar" which takes the place of servlet.jar and you will need to add it to your class path when compiling your Servlets.

You would do well to go through some of the Apache Tomcat documentation. Start with http://tomcat.apache.org/tomcat-4.1-doc/appdev/ but be prepared to use your favorite search engine.
 
Bear Bibeault
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That link points to the docs of Tomcat 4 which is antiquated. Be sure to be using Tomcat 6 or 7.
 
Keano Denton
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also I am using a Mac running OS X 10.8.4. I don't know if that matters. I've done some research on Tomcat, and set it up on my mac, but I keep getting exceptions when running the catalina.sh in terminal. Thanks for all your help
 
Bear Bibeault
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Keano Denton wrote:Also I am using a Mac running OS X 10.8.4. I don't know if that matters. I've done some research on Tomcat, and set it up on my mac, but I keep getting exceptions when running the catalina.sh in terminal. Thanks for all your help



Doesn't matter -- I'm using 10.8.4 as well. Tomcat 6 runs fine for me.

You shouldn't be running catalina.sh but startup.sh.

Make sure that JAVA_HOME is properly defined. For me:

$ echo $JAVA_HOME
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

 
Keano Denton
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I downloaded and installed Tomcat 8. It was the latest version. Should I remove it and use 6 or 7?
 
Bear Bibeault
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat 8 is an alpha. I would advise using a stable version.

I run Tomcat 6 because that's what my clients are using.
 
Keano Denton
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. So I have deleted version 8 and installed version 7. I got everything configured and can now get tomcat running in a browser window. Now where do my class files and html files go in the tomcat directory?
 
Bear Bibeault
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A web application requires a specific structure. You can see the Servlet Spec, the Tomcat docs, or a servlet tutorial for the structure.

A quickie overview for one fairly easy way to do it:

  • Create a folder in webapps. This serves as the context root, and its name becomes the context path.
  • Create a folder named WEB-INF in the context root. Not web-inf, not Web-inf, not Web-Inf, it must be WEB-INF.
  • Within WEB-INF, create the deployment descriptor (web.xml).
  • Create folder WEB-INF/classes. Your package hiearchy goes here.
  • Make sure all classes are in a package other than the default.
  •  
    My honeysuckle is blooming this year! Now to fertilize this tiny ad:
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!