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
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
John, Since you're a greenhorn, I suppose it would only be fair to tell you how things work around here:
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,
Don't post the same question to multiple forums. This creates more work for the moderators.
It's the forum moderator's prerogative to move your post to another forum if he/she feels that it is more relevant there.
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
Joined: Dec 19, 2001
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.
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.
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.
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.
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
Joined: Dec 19, 2001
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 !.
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
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
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.
Joined: Dec 19, 2001
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://126.96.36.199: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 !
Joined: Mar 09, 2001
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 !.
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).]
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.