• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Classpath setting trouble

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
     
    reply
      Bookmark Topic Watch Topic
    • New Topic