wood burning stoves*
The moose likes Servlets and the fly likes Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Tomcat" Watch "Tomcat" New topic
Author

Tomcat

Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
This is going to be a really dnb guestion so no jokes please since I am very new to servlets.....
I have tomcat up and running. No problems with classpath or anything. Now how do I get my .class files running on it. And once I 'upload' them, how can I access them through a browser?
I think I understand the HttpRequest and HttpResponse, but I'm not sure how to get it to run?
I know with a web page, you can upload your html files using an ftp, and then an applet encoded in html runs using the html code. This I have done without problem. What about servlets???
Thanks in advance!!
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
You need to upload your .class files to the web-inf/class folder.. Lets say you have a HelloWorld.class in that folder for tomcat running at http://localhost:8080
What you would do is enter http://localhost:8080/servlet/HelloWorld in your browser window and the .class should be executed and you should see the result printed to your browser (provided you did a out.write from PrintWriter).

[This message has been edited by Mak Bhandari (edited April 24, 2001).]
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Thanks Mak for your reply.
When you say upload, how do I do that? Do I use ftp? or do I save it on my hard drive and it is automatically uploaded when I start tomcat?
And how do other people view it? How could every one have http://localhost:8080 as their initial destination???
Thanks in advance. There must be something so obvious and I am missing it.
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
to answer your question, please let me know the environment where you are running tomcat.. Server, DOmain Name, WebServer etc ..
Vladan Radovanovic
Ranch Hand

Joined: Mar 20, 2000
Posts: 216
1. You just copy ( save) your class file to the classes directory.
2. If you want someone else to view your servlets, You find out what is your ip address and they can substitute that number in place of "localhost" and then they will be able to invoke it.
Vladan
Originally posted by Brian Snyder:
Thanks Mak for your reply.
When you say upload, how do I do that? Do I use ftp? or do I save it on my hard drive and it is automatically uploaded when I start tomcat?
And how do other people view it? How could every one have http://localhost:8080 as their initial destination???
Thanks in advance. There must be something so obvious and I am missing it.

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Brain:
Please refer to this post, I have posted somde detail steps
here, which seem to be working..... http://www.javaranch.com/ubb/Forum7/HTML/003090.html
Also, Tomcat is one of our very frequent topic for discussion.
So a search could help you faster.

Mak:
to answer your question, please let me know the environment where you are running
tomcat.. Server, DOmain Name, WebServer etc ..

Not sure why you asked this
As I understand,
environment: (OS) doesn't matter
Server: Tomcat
Domain Name: localhost
WebServer: Tomcat.
Don't you think its that obvious or am I missing something.....
regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
environment as in whether he is running it on his standalone machine.. with tomcat running on 8080 without PWS/IIS/APACHE or is he extending it ? Or does he have a dedicated server with a domain name on the net ?
His problem is in not knowing how to access it.. (ftp the file or copy the file leads me to wonder) Thats the reason behind my q.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

oh! I was just curious. Thanks for the clarification.
- satya
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
I am running it off my computer at home. I've been able to access http:/localhost/8080 when tomcat is up. Another words, when I go to http:/localhost/8080 with tomcat IS NOT running, the server does not detect it. When tomcat IS running it goes to the default tomcat page. Is this page like my index file in html??
Vladan,
When you say:

You just copy ( save) your class file to the classes directory.

Is that the classes directory on my c:\ drive?
and

You find out what is your ip address
and they can substitute that number in place of "localhost"

Where do I get the ip address from?

Where do I go from there?? Sorry if I'm missing something.
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
I think I am also thinking that my computer needs to be up and running for the servlet to work? or are my servelets placed on a server somewhere other than my macjhine??
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Brian, Yes, your computer has to be running tomcat if you want to be able to run your servlets/JSP's. Put your class files in the follwing directory under tomcat. /webpages/WEB-INF/classes/.

Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Thanks Bosun,
How to other people view it was my other question. How do I find out the ip address??
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

when you run on your machine (not connected to a network),
you will use the localhost. This is a defined std.
It also can be referenced by the special IP address:
127.0.0.1
When you are connected to a network, you will get a IP
address from your ISP provider. You can find this out by
the command nslookup if its supported on your system.
Then using this IP address, others (world) can connect to your
system and look at your servlets/JSP which you will host,
through a PORT (which by default is 8080 for Tomcat).
Please take a look at the networking tutorial on the Sun
website or refer to a book on networking.
regds.
- satya
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Thanks again for the help. You really got me going in the correct direction.
My new problem is that the .java file won't compile beacuse when I import javax.servlet I get an error that it can not be found. I've been reading previous posts and they all mention a tools.jar file in my classpath. These posting use an earlier verison of the JSDK .
Well, I jave jdk1.3.0_02 and the tools.jar file is in c:\jdk1.3.0_02\bin and my classpath is set to c:\jdk1.3.0_02\bin\tools.jar and it still won't compile. Should I have another .jar file in my classpath for this version?
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

thats' in the tomcat_home\lib folder.
add all the jar files in the TOMCAT_HOME\lib
folder to the classpath and then compile...
its not part of the jdk. the app servers
provide the implementation for the interfaces.
You are doing good, carry on!
regds.
- satya
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
I downloaded the servlet.jar file and all is working now. Your few steps really helped me out.
Many thanks!!

Chris Cingrani
Ranch Hand

Joined: Nov 21, 2000
Posts: 69
I know Brian got his problems worked out, but I thought other people who might be checking out this post might need some additional information. I found this link by doing a search on JavaRanch a few weeks back. When I went to setup Tomcat, this is the article I used. It provides step-by-step setup instructions with screen shots. Hope it helps...
http://www.oreillynet.com/pub/ct/33
Chris
[This message has been edited by Chris Cingrani (edited April 25, 2001).]
Brian Snyder
Ranch Hand

Joined: Feb 03, 2001
Posts: 142
Thanks Cindy that was a great link. There have been many posts on this website involving problems of the same nature and this web site answers them all clearly without missing any steps.
Many thanks!!
Brian
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Good link Chris.
From now on, I will start refering other to the same.
regds.
- satya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat
 
Similar Threads
Ajax in Tomcat
Java FileUploading
Upload file
Uploading Images via browser
File Uploading