ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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?
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.
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.
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.
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 .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.