File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes TOMCAT - Path to GIF files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "TOMCAT - Path to GIF files" Watch "TOMCAT - Path to GIF files" New topic
Author

TOMCAT - Path to GIF files

John Thomas
Greenhorn

Joined: Dec 19, 2001
Posts: 8

I guess I should have phrased my earlier question properly.
My question was which directory in TOMCAT should I put the GIF files that the Servlet uses.
My Tomcat is installed at c:\jak-tomcat
I copy the Servlet classes ( e.g. Serv01.class ) to
c:\jak-tomcat\webapps\ROOT\WEB-INF\classes
I access the Servlet using
http://localhost:8080/servlet/Serv01
My question is, in the HTML that the Servlet (Serv01) generates, if I want to include a GIF file ( pic01.gif ) as part of a IMG tag could someone please tell me how to code the path for SRC parameter ?.
Thanks
John

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

John,
Your post was not closed because it was not clear: it was closed because the moderator here thought that it was more appropriate in the HTML forum. Please see my answer there. Also, next time please try to double check the reason your thread was closed before reposting.
Thanks and welcome to JavaRanch!
Junilu


Junilu - [How to Ask Questions] [How to Answer Questions]
John Thomas
Greenhorn

Joined: Dec 19, 2001
Posts: 8
Why should this question be posted under HTML and JavaScript forum ?. I believe my issue has more to do with TOMCAT.
Again, the gist of my question was where should I place the GIF files that the HTML generated by a Servlet needs and how should I code the path in the SRC parameter of IMG tag. So that when I access the Servlet using TOMCAT ( standalone mode ), TOMCAT is able to locate the GIFs.
I have posted the same question under TOMCAT forum, so far no one
has posted any replies.
Thanks for taking the time to answer my question.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

John,
Since you're a greenhorn, I suppose it would only be fair to tell you how things work around here:

  1. Moderators are all volunteers: we don't get paid and we do this because we want to. The folks who answer questions do so on their own time, too, for free. You may not get an answer as quickly as you want so please be patient. So,
  2. Don't post the same question to multiple forums. This creates more work for the moderators.
  3. It's the forum moderator's prerogative to move your post to another forum if he/she feels that it is more relevant there.

  4. As for your question, it doesn't really have a whole lot to do with TOMCAT per se. You just need to understand how your current context is affected when you're using servlets to generate responses. As such, I tend to agree that your post does not belong in the HTML forum. But then like I said above, it's the forum moderator's call.
    That said though, did you try out the suggestion I made in my reply in the HTML forum?
    Junilu
John Thomas
Greenhorn

Joined: Dec 19, 2001
Posts: 8
Junuli,
I wasn't challenging the moderator's authority, but rather had a disagreement on classifying my post under HTML & JavaScript
I wish you concentrated more on the subject matter rather than wasting your time explaining the lack of monetary benefits.
Also, I don't think you are qualified enough to be a moderator because the very suggestions that you made for my problem is ample evidence of your lack of knowledge in the fundamentals of TOMCAT.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Normally I'd stay well away, but I'd like to point out that Junilu has amost 1000 posts to Javaranch. Even with general boo-keeping and conversation I think it reasonable to say he's helped several hundred (4-500?) people. Doesn't mean he deserves your respect or admiration, but it does indicate his skill and dedication.
Anyway, this thread is getting off topic and is in danger of getting moved to the Javaranch Forum
Also, I don't think you are qualified enough to be a moderator because the very suggestions that you made for my problem is ample evidence of your lack of knowledge in the fundamentals of TOMCAT.

Sounds like a personal comment to me, and we don't take kindly to that 'round these parts :}
Can we get some info from you on your setup, whats the name of your web-app (whats the context), how have you set up the directory structure etc. I've never run into a similar problem, but if we can compare how you have things set up to mine we should be able to find a solution.
Dave.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

OK, I re-read your question (got distracted by the arguments)
and I've had problems with the ROOT context too, the problem being it doesn't seem to like sub-directories (it thinks they refer to other contexts)
Simple solution is put the image in the ...\ROOT\ directory and refer to it as ... SRC="/pic01.gif"
I'll go see if I can find a solution to the whole "subdirectories-in-the-ROOT-context-in-Tomcat" thing.
Dave.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Nup, tries the Tomcat docs, Javaranch and Google but couldn't find any solutions.
Looks like you'll have to create a "real" context and then you can safely refer to sundirectories within that context.
If you do find a solution to this I'd be interested in hearing it,
ta,
Dave.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
I did misread your question when I closed it the first time. I agree that it should not have gone to the HTML forum. My mistake.

------------------
Matthew Phillips
Sun Certified Programmer for Java 2 Platform


Matthew Phillips
John Thomas
Greenhorn

Joined: Dec 19, 2001
Posts: 8
Thanks for the update David !.
- John
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
In your HTML, put this attribute in the body tag:
onload="alert(location.pathname)"
This will tell you exactly what your path is. It's probably:
http://localhost:8080/servlet/Serv01
like you said your URL is.
You could also try location.hostName which theoretically should give you the root of the website (probably http://localhost:8080/)
Then for the image tag href attribute, you can either give it the absolute URL, or figure out the relative URL and do it like that, which is probably:
href="../images/pic.gif"
or try
href="/images/pic.gif"

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

John,
Expertise is not a pre-requisite for moderatorship. Willingness to help others is. It also helps if you have broad shoulders and confidence enough in your own knowledge to shrug off remarks like those you made.
True, I do not know a whole lot about Tomcat as I have been working intensively with VisualAge and WebSphere for the past nine months. However, I am quite confident that I understand the basics (and perhaps a bit more) of how web servers and servlets/JSPs work.
So, I reiterate that I do not think that your issue has anything to do with Tomcat specifically. What you need to understand is the basics of the contextPath. If you understand that, you will realize that you can put your images anywhere on the Internet as long as you know how to get to them. Then you will know what to put in the IMG SRC tag.
Good luck,
Junilu
Originally posted by John Thomas:
Junuli,
I wasn't challenging the moderator's authority, but rather had a disagreement on classifying my post under HTML & JavaScript
I wish you concentrated more on the subject matter rather than wasting your time explaining the lack of monetary benefits.
Also, I don't think you are qualified enough to be a moderator because the very suggestions that you made for my problem is ample evidence of your lack of knowledge in the fundamentals of TOMCAT.

John Thomas
Greenhorn

Joined: Dec 19, 2001
Posts: 8
Sure, Expertise in TOMCAT is a MUST to be a moderator's helper.
Even the MODERATOR agrees that my issue IS related to TOMCAT
I don't understand what your freakin problem is !.

Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4456
    
    6

John,
I have no problem and there is really no reason for you to be hostile or rude. At any rate, I asked a colleague at work about Tomcat configuration of subdirectories and he said he did have problems getting to files in subdirectories. I suggest you try looking into one of the configuration XML files for Tomcat. You still have not posted any information about your configuration -- that would be helpful. Which version of Tomcat are you using?
Also, check out the HTML source in this link: http://jakarta.apache.org/tomcat/tomcat-4.0-doc/appdev/sample/web/
The IMG SRC link is exactly the way I suggested to you before.
Junilu


ernest fakudze
Ranch Hand

Joined: Aug 27, 2001
Posts: 216
John Thomas:
Didn't anybody ever tell yout that being rude does not promote a healthy
society? To me you seem like a very angry person and you clearly have severe
attitude problems. I can't believe that you can make such a big fuss just because you were misunderstood. Why can't you jsut be nice? People will like you more.
Nice people brighton others' lives and we all learn something from them.
May I also remind you that JavaRanch is supposed to be a friendly place, not a
battlefield. You wanna have a close encounter with war, go to Afghanistan.
You don't have to reply now. Just look inside you and think, think about how you can be a better person. At least for 2002. Lastly, don't challenge authority because you can never win and know when to let it go!


In a time of drastic change it is the learners who inherit the future. The learned usually find themselves equipped to live in a world that no longer exists.<br />Eric Hoffer
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Yeah, pull your head in, you two!
Don't make me turn the hose on you!
Um, I keep getting distracted, have we solved the problem or are we just arguing now? If we're still arguing I can get the thread moved to MD if you want.
Dave.
John Thomas
Greenhorn

Joined: Dec 19, 2001
Posts: 8
David,
Finally I figured out , where to place the GIFs and how to code it in SRC parameter
As I said earlier, I copy all my Servlet classes to
C:\jak-tomcat\webapps\ROOT\WEB-INF\classes

Copied my GIF file (pic01.gif) to
C:\jak-tomcat\webapps\ROOT\

In my HTML file, for the SRC I coded
SRC='/pic01.gif'
(If Windows Explorer's properties say the pic01.gif is PIC01.GIF then you need to code in upper case )
What I was missing was the slash '/' before pic01.gif
The above solution is for a TOMCAT installation out of the box, with no changes to server.xml or any new Context entries.
In case you wondered how I figured this out...
Internet Explorer , when it is unable to load a pic shows a cross ( X ) at that particular location . Right click on the cross and under properties it will tell you the actual path where it tried to load from .
In my case it was http://122.76.141.31:8080/servlet/pic01.gif , which led me to believe that TOMCAT expected pic01.gif at the root, which prompted me to put a '/' before pic01.gif
Thanks for all your help !
Junuli, you are a nice guy. I should have appreciated your well intentioned replies.
Ernest, Pope in Italy needs people like you !

Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Originally posted by John Thomas:
Sure, Expertise in TOMCAT is a MUST to be a moderator's helper.
Even the MODERATOR agrees that my issue IS related to TOMCAT
I don't understand what your freakin problem is !.


Actually, I said no such thing. I simply said that I made a mistake by moving this to the html/javascript forum. If I thought it was a Tomcat issue, I would have moved it to the Apache/Tomcat forum.
For future reference, we do request that topics be posted in the most appropriate forum only. If you feel that you have a Tomcat issue, please post your question there instead of (or in addition to) here.
Please understand that just because a person's profile states that he/she is a bartender/sheriff does not mean they know what the problem you are having is. If you do a search on my name in servlets you will see that I have provided very little assistance in this forum. My willingness to assist javaranch and my assistance in other forums put me in the position of moderator.

Let us all remember that this is a friendly place and keep it that way. Thanks.
------------------
Matthew Phillips
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Matthew Phillips (edited December 21, 2001).]
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

Hi John,
I use Tomcat 4.0.1 under Windows 2000 server and access my servlets by http://localhost:8080/examples/servlet/ServletName where "ServletName" servlet is stored in <b>webapps/examples/web-inf/classes</b> directory. I store my images in <b> webapps/examples/images</b> directory and load them in my servlet or jsp pages thru <b>webapps/examples/images</b> directory. U may try in this way....

------------------
Muhammad Ashikuzzaman (Fahim)
Sun Certified Programmer for the Java� 2 Platform
--When you learn something, learn it by heart!


Ashik Uzzaman
Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TOMCAT - Path to GIF files