• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiling Servlet  RSS feed

 
maya dox
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Am new to servlets and have question with regards to its compilation. First: Do i need to install j2ee to compile a servlet??? because when am trying to compile the below servlet even after setting the class path for servlet-api.jar, am displayed "cannot find HttpServlet, cannot find out.println" and so on. below mentioned is the code


import java.io.*;
import javax.servlet.*;

public class Myfirstser extends HttpServlet


{

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException


{


res.getContentType("text/html");

PrintWriter out = res.getWriter();

out.println("print this servlet message");

}

}

how do i compile the servlet by using command prompt??

Kindly help me out with this.

Thank you all.

Duke
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need a Server to compile. Having the servlet-api jar on the class path should work. A servlet is just a Normal java class that extends from HttpServlet. Normal java rules apply!!
 
maya dox
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes even after placing the class path for servlet-api.jar i get those error. any idea please???
 
Smitesh Shinde
Ranch Hand
Posts: 45
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please take some pain to paste the error you are getting while compiling your servlet?
 
maya dox
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
heheheh yes sure. the error was HttpServlet not found, out.println not found and so on.

But i got. I got my classpath correct and its working fine. I copied the servlet-api.jar file to jdk>>jre>>lib>>ext directory and pasted the same in the class path.

Earlier i had copied the same jar file jdk/lib folder!!.

Thanks and sorry for trouble.

Hoping to learn a lot from you all and from this code ranch.

thanks once again.
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Pubudu Fernando
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii.. this is the same problem i have i'm a complete newbie to J2EE as well... i was gonna try what maya dox had suggested... but there wasn't any jar file which had "servlet" in its file name :S i've installed J2EE 5... any suggestions please?? (oo and this the site of the people who wrote head first jsp and servlets right? i just wanted to make a suggestion for the next edition...please include more detailed information about setting up your computer to work with J2EE and about how to test whether we managed to set it up properly..)
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You have managed to ask two questions in the same thread. I would suggest you repeat the question about the books on our books forum, and we shall continue to answer the compiling question in this current thread.
 
Pubudu Fernando
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah no... the thing about the book wasn't a question.. twas a suggestion (in hope that the authors themselves would see it or someone else might point it out to them)

and i've managed to sort out the compilation issue... i just copied the jar file named j2ee to the location maya mentioned.. thanks alot! i've been looking for this info for some days now
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest starting to use an IDE if you have moved on to J2EE. Hand compiling java code is a good thing to start and learn, but once you think you want to move into the the J2EE space - you should be comfortable to start using an IDE. Eclipse/Netbeans are easy enough to start using and all the lib/jar issues are much more simple to address!
 
Campbell Ritchie
Marshal
Posts: 56553
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still think you are more likely to get attention about the book if you start another thread on our books forum.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@maya : look at your import statement part, did you miss something there?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tag, while posting your code . so that your code can be easy to read, hence probably you will get more reply.
 
maya dox
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. thanks
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!