tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Kjome <>
Subject Re[6]: file path problem
Date Tue, 07 May 2002 15:31:39 GMT
Hello Bharanidharan,

Glad I could help :-)

As for your new question....well, only if you loaded the template in the servlet and then
had the
servlet return the result in the response.  You wouldn't be able to
get a direct connection to the template inside the WEB-INF directory
from a browser requested http call.  You can access anything you want
anywhere on your system on the server-side with Java.

What are these "templates"?  Are they html files that are supposed to
be served up by the web server without modification?  To me,
"template" means that it provides a general structure that is ready to
be filled in with data.  That would be done by loading the template up
in the servlet, dynamically adding data where specified in the
template, and then returning the result of the structure + data to the
web client.

Maybe I'm misunderstanding something because I've never worked with
jetspeed, but that should be the way it works.


Tuesday, May 07, 2002, 8:36:10 AM, you wrote:

MB> jake,
MB>       your explanation is excellent. I completely understand whats going on
MB> now.. but again a quick question.. In jetspeed, we have template files under
MB> Web-inf directory but the template directory is mapped in
MB> file. So i should be able to access the
MB> templates under Web-inf directory as jetspeed does. 

MB> thanks
MB> bharani.

MB> -----Original Message-----
MB> From: Jacob Kjome []
MB> Sent: Monday, May 06, 2002 5:40 PM
MB> To: Tomcat Users List
MB> Subject: Re[4]: file path problem

MB> Hello Bharanidharan,

MB> Ah, I didn't see that before.

MB> You don't want to store your static files under WEB-INF.  That is
MB> purely for servlets and other general classes and some config stuff
MB> such as the web.xml that you don't want to have directly accessible
MB> via the web.

MB> You would put your html file one directory up from WEB-INF in your
MB> "jetspeed" directory.  This is also where you would put .jsp files.

MB> Also, you don't actually have to provide the /servlet/* mapping in
MB> your own web.xml.  You will get that functionality already because it
MB> is in Tomcat's default web.xml.  All you need to know is that it is
MB> the functionality that it provides.

MB> Now, keep in mind that nothing within WEB-INF will be accessible
MB> without some sort of mapping.  We are using the default /servlet/
MB> mapping that Tomcat provides.

MB> So, when you see:


MB> The "/servlet" part of of that URL is virtual.  The mapping is
MB> provided by the web server.  The request goes through an invoker
MB> servlet that runs the requested servlet for you.  That is much different
MB> than going to your
MB> html file which should be at...

MB> .html

MB> Although, that assumes that you would move the root of "templates"
MB> into the "jetspeed" directory rather than have it exist under the
MB> WEB-INF directory.

MB> As you can see, the server needs no mapping information for static
MB> files other than knowing what directory or virtual directory
MB> points to.  After that, you just
MB> follow the directory structure within the "jetspeed" directory to
MB> determine the URL path to the static document.  This is not so with
MB> servlets.  You can't just browse to a servlet at some physical path on
MB> the disk.  You refer to servlets through servlet mappings.

MB> BTW, if you created a directory called "servlet" to store static
MB> files, you wouldn't be able to get to them because Tomcat would
MB> intercept the pattern /servlet/ and try to map the named entity that
MB> comes after that rather than serving the named entity directly from
MB> that directory.

MB> For instance, if you had:
MB> /webapps/jetspeed/servlet/templates/vm/navigations/html/loggedinportlet.html

MB> and tried to get to that page via:
MB> nportlet.html

MB> Tomcat would report an http 404 error because it tries to find a
MB> servlet to invoke named
MB> "templates/vm/navigations/html/loggedinportlet.html" or with a
MB> class name of "templates/vm/navigations/html/loggedinportlet.html"

MB> Which brings to mind another trick.  You can name your servlet and get
MB> there via the servlet-name rather than having to specify the whole
MB> package + Servlet class name adding the following to your web.xml:

MB> <servlet>
MB>         <servlet-name>newlogin</servlet-name>
MB>         <servlet-class>myclasses.NewLogin</servlet-class>
MB> </servlet>

MB> Now you can get to your servlet via the class-name:


MB> or via the servlet-name:


MB> You can also, then, provide your own mapping for the servlet named
MB> "newlogin" such as:

MB> <servlet-mapping>
MB>         <servlet-name>newlogin</servlet-name>
MB>         <url-pattern>/login</url-pattern>
MB> </servlet-mapping>

MB> which allows you to get to your servlet without having to go through
MB> the default /servlet/ mapping like this:


MB> notice that the "servlet-name" in "servlet" and "servlet-mapping" must
MB> be *exactly* the same (case sensitive too).

MB> Does that make more sense or did I just add to the confusion?

MB> Jake

MB> Monday, May 06, 2002, 3:14:21 PM, you wrote:

MB>> Jack.. i am sorry its very complicated for me and i didnt understand
MB>> anything you said.. I am new to tomcat environment. 

MB>> I have a servlet under
MB>> /webapps/jetspeed/Web-inf/classes/myservlet/NewLogin.class. In that
MB> servlet
MB>> i have to call a html file that is kept under
MB> /webapps/jetspeed/Web-inf/templates/vm/navigations/html/loggedinportlet.html
MB>> . 

MB>> I have the following code in web.xml

MB>> <!-- The mapping for the invoker servlet -->
MB>>   <servlet-mapping>
MB>>     <servlet-name>invoker</servlet-name>
MB>>     <url-pattern>/servlet/*</url-pattern>
MB>>   </servlet-mapping>

MB>> how do i map the html file in my NewLogin.class servlet. i still dont
MB> get
MB>> how the webpath is mapped to the system file path... 

MB>> sorry for the inconvenience.

MB>> please let me know..

MB>> thanks
MB>> bharani.
MB>> -----Original Message-----
MB>> From: Jacob Kjome []
MB>> Sent: Monday, May 06, 2002 3:52 PM
MB>> To: Tomcat Users List
MB>> Subject: Re[2]: file path problem

MB>> Hello Bharanidharan,

MB>> /servlet/ is a mapping provided for you by Tomcat.  In fact, take a
MB>> look in the web.xml in $TOMCAT_HOME/conf and look for that mapping:

MB>> <!-- The mapping for the invoker servlet -->
MB>>   <servlet-mapping>
MB>>     <servlet-name>invoker</servlet-name>
MB>>     <url-pattern>/servlet/*</url-pattern>
MB>>   </servlet-mapping>

MB>> If tomcat didn't provide this, you would have to set up a mapping for
MB>> each and every one of your servlets that you wished to run.  With
MB>> this, you can run any servlet in your webapp by naming the servlet
MB>> with the full package name.

MB>> When you want a more convenient URL to invoke your servlet, you can
MB>> provide your own mapping in a similar way as the above example in your
MB>> own web.xml.

MB>> Keep in mind that the /servlet/ mapping is *not* guaranteed to exist
MB>> across containers, although I would imagine that a number of
MB>> containers might just copy Tomcat's lead on this to be compatible.

MB>> Jake

MB>> Monday, May 06, 2002, 2:16:11 PM, you wrote:

MB>>> jack,
MB>>>     I have a quick question. in your example below, i.e.


MB>>> you mean to say "servlet" in the URL is mapped to "Web-inf" directory
MB>> under
MB>>> jetspeed??.. i am still unable to comprehend the url path.

MB>>> thanks
MB>>> bharani

MB>>> -----Original Message-----
MB>>> From: Jacob Kjome []
MB>>> Sent: Monday, May 06, 2002 1:08 PM
MB>>> To: Tomcat Users List
MB>>> Subject: Re: file path problem

MB>>> Hello Bharanidharan,

MB>>> Don't confuse the system file path with the URL path.

MB>>> What URL is in your browser on the page that contains the

MB>>> will try to find the page relative to your domain root.

MB>>> If you are at:


MB>>> Then the code you have for will be attempting to find a
MB>>> directory on the server that simply doesn't exist.  You would be able
MB>>> to get to your "myhtml" directory with this, though.


MB>>> However, you can't count on this, because what if you did a servlet
MB>>> mapping and you got to your login servlet via:


MB>>> now, the proper way to get to your html page would be:


MB>>> The issue here is that you are hard-coding a path that can't be
MB>>> assumed.  What you should do, instead is the following:

MB>>> out.println("\"" + req.getContextPath() +
MB>>> "/myhtml/loggedin.html\")";

MB>>> After doing this, it doesn't matter where you invoke your servlet from
MB>>> as long as the static html is in the proper location relative to the
MB>>> root of the webapp.

MB>>> Jake

MB>>> Monday, May 06, 2002, 11:30:37 AM, you wrote:

MB>>>> Hi all,
MB>>>>        I have my login servlet under
MB>>>> webapp/jetspeed/web-inf/classes/myservlets/login.class. I invoke a
MB>>>> loggedin.html from this servlet. loggedin.html is located under
MB>>>> webapps/jetspeed/myhtml/loggedin.html. so in my servlet, i gave 


MB>>>> but apache gives error saying resource /myhtml/loggedin.html couldnt
MB>> not
MB>>> be
MB>>>> found. I tried copying this file to various directories including the
MB>>>> template directories under jetspeed but no success.. can someone how
MB>> the
MB>>>> file path is specified in jetspeed..

MB>>>> thanks
MB>>>> bharani.

MB>>>> --
MB>>>> To unsubscribe, e-mail:
MB>>> <>
MB>>>> For additional commands, e-mail:
MB>>> <>

Best regards,

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message