This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Classpath setting trouble Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Classpath setting trouble" Watch "Classpath setting trouble" New topic
Author

Classpath setting trouble

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
Hi Ranchers,
I have planned to learn servlets and java in Netbeans IDE( I used netbeans for SCJP learning). I heard that netbeans will start tomcat by itself. No need to install tomcat seperately. Can anyone please help me how to set the classpath. I already set in command prompt like

C:\java>set CLASSPATH=.;C:\Program Files\netbeans-4.1\enterprise1\jakarta-tomcat
-5.5.7\server\lib\servlet.jar

But the above one compiled well but when I executed it didn't give result.
Please help me in classpath setting in netbeans.
[ February 07, 2008: Message edited by: Shiva Mohan ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I don't think you have to set a classpath like that if you are running Tomcat from NetBeans.

Can you be more specific than "it didn't give result"? What DO you get?
[ February 07, 2008: Message edited by: Marc Peabody ]

A good workman is known by his tools.
Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
Hi Marc,

Thanks for the reply. sorry and currently,I am getting the error message
javax.servlet doesnot exist when I tried to run the program at IDE.

I am trying to run the below program




How would I make sure netbeans tomcat is working properly.How to statrt,stop or restart tomcat engine in netbeans IDE? Please help.

[ February 07, 2008: Message edited by: Shiva Mohan ]

[ February 07, 2008: Message edited by: Shiva Mohan ]
[ February 07, 2008: Message edited by: Shiva Mohan ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

1) Make sure you've created a Web Project (File>New Project>Web>Web Application). The wizard will let you choose an instance of Tomcat.
2) Do not put your code in the default package. This is generally bad practice and NetBeans especially hates it.
3) Get rid of the main method in your Servlet.
4) service() isn't the best method to override. doGet() would be more appropriate here. Don't worry about changing until after you get this working.
5) You need to map the Servlet in your web.xml. If you used the NetBeans wizard to create the Servlet, it will automatically create this mapping for you. (File>New File>Web>Servlet)
6. To start Tomcat, simply click the Run Main Project "play button" at the top or press F6. The build and Tomcat startup should display in your console window at the bottom. It will also automatically open a browser window pointing to the welcome page (index.jsp if you created your project with the wizard), which you my add Main to the end of the URL. There you'll see your Hello World
Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 477
Thanks a lot Marc. That really helped to clear most of my doubts. But I have got the following error.
Also, I don't understand step 5. But you told me that will create automatically by netbeans. Did you mean,configuration files folder that has web.xml
file and when I openened that that showed Display name,Describtion,session timm out. Do I need to set anything here.
Please help on this one too.

HTTP Status 404 - /Hello/HelloWorld

type Status report
message /Hello/HelloWorld
description The requested resource (/Hello/HelloWorld) is not available

My Updated coding is


[ February 07, 2008: Message edited by: Shiva Mohan ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I don't understand step 5.

You need to map your servlet to a URL. In web.xml, you need the following:


Marc is telling you that if you created the servlet using Netbeans' wizard (which you probably have not), this will be done automatically.

And for some personal comments
  • Main is an awful name for a servlet
  • You should put your servlet in a package to avoid troubles


  • (If this discussion goes on about how to use Netbeans, it will be moved to the IDE forum)
    [ February 07, 2008: Message edited by: Christophe Verre ]

    [My Blog]
    All roads lead to JavaRanch
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Classpath setting trouble