LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-28-2006, 07:39 AM   #1
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Java and Servlets. Do I need J2EE?


Hi there!

Could somebody please give me a hand. I'm trying, for the first time, to create a HelloWorld servlet. However, I can't extend the class HttpServlet:

Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SomeServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
      
  
    PrintWriter out = response.getWriter();
    // Use "out" to send content to browser
  }
}
I don't think there's anything wrong with the code itself. Eclipse reports two errors:

"the import javax.servlet cannot be resolved" and "HttpServlet cannot be resolved to a type"

I have been searching google for a while and looks like I need servlet.jar in my path, which I have no idea where to get from. Sun's homepage points me to J2EE. Can anybody show me some light?

Thanks in advance!
 
Old 03-28-2006, 09:07 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OEL
Posts: 9,165

Rep: Reputation: 243Reputation: 243Reputation: 243
You certainly need J2EE (JavaEE now).

Servlets are a major component of the EE model.

Even while you can pick servlet.jar somewhere to complete the compilation, you'll need a servlet container to run it.

There are a lot of free and open source servlet containers (a.k.a web app containers, a.k.a. application servers when they support EJB) available, tomcat, glassfish, jboss, ... and commercial ones too.

Last edited by jlliagre; 03-28-2006 at 09:08 AM.
 
Old 03-28-2006, 09:32 AM   #3
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 50
You can find the servlet libraries in a servlet container like tomcat, jetty or resin. When you have downloaded one of them, you can import the jar in eclipse or whatever ide you are using.


Hope this helps
 
Old 03-28-2006, 11:20 AM   #4
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Original Poster
Rep: Reputation: 63
Thanks a lot guys . It seems to be compiling now at least. I've installed Tomcat and the server is running great. I did not find any servlet.jar with it. I also downloaded and installed JavaEE and did not find anything similar to servlet.jar. Interesting enough though, I downloaded EclipseWTP and it had the servlet.jar on the plugins folder. Pretty much the way I've installed JDBC drivers, I simply copied the servlet.jar to my /jre/lib/ext folder and I got the above program to compile.

I've to know read a little more on the book to learn how to run the application. I thought it would be as easy as copying the HelloWorld.class file to the /WEB-INF/classes directory, but it's not all that easy apparently.

Well, I will keep trying. Looks a hell lot harder I thought it should be

Thanks again!

Last edited by Mega Man X; 03-28-2006 at 11:21 AM.
 
Old 03-28-2006, 01:03 PM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OEL
Posts: 9,165

Rep: Reputation: 243Reputation: 243Reputation: 243
The jar file containing javax.servlet classes can have another name than servlet.jar, it really just need to be in the classpath.

I believe it is named j2ee.jar with Sun's JDK and servlet-api.jar with Tomcat.
 
Old 03-28-2006, 01:27 PM   #6
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Original Poster
Rep: Reputation: 63
Thanks again jlliagre!. I will keep this for future reference . Well, I've got the servlet to run as it should. Man, it was no easy task installing and configuring everything. Now I'm trying to be able to start dynamic projects with Eclipse and even being able to start/stop Tomcat from within it. Computers at my class are configured that way .

I've done a few dynamic php pages before and it was not all difficult, but JSP/servlets will take some time getting used to .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tomcat can't find th servlets! xpucto Linux - Software 1 03-23-2006 12:46 PM
Object Reference problem in Java servlets Hockeyfan Programming 1 06-16-2005 01:36 AM
hypothetical qu; java servlets for streaming audio? german Programming 0 02-03-2005 11:44 AM
servlets/jsp/j2ee linux_ub Linux - Software 1 09-29-2004 02:17 PM
how do i set up a webserver using mandrake 10 to use java servlets almvtb Mandriva 0 06-29-2004 03:21 PM


All times are GMT -5. The time now is 04:41 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration