You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Spencer Tickner <sp...@gmail.com> on 2007/12/18 18:56:02 UTC

Servlet File Structure

Hi List, thanks in advance for the help.

I'm fairly new to tomcat so I appologize for anything I say that may
be painfully obvious.

I've set up a security servlet that will check permissions on various
html, pdf, xml, etc, files. I've managed the security and caching and
filtering so this is not my problem.. My problem is something that
should seem to be much more simple ergo,, incredibly more agravating
for me ;) I don't know where to put all these files.

1) I started with the content files out of the Web directory all
together and kept the mapping in an xml file and then served them
using FileInputStream and writing them to the ServletOutputStream.
This doesn't work because any internal refrences (<img>, <style>,
etc.) are lost.

2) My next attempt was to put them into the Servlet folder which
worked until I had to reload the .war file.. Which promptly got rid of
all the content. I considered adding the content to the war file,, but
this isn't so good because it would be nice for the application
developers to work seperately from the editors which already have
there own proccesses for managing content.

3) My last attempt is to put the content outside the Servlet folder,,
but then I can't figure out how to map the servlet filter to fire when
someone requests a file.

I have spent a considerable time looking through Google, but still
have not found an answer.. Any help would be very appreciated.

Thanks,

Spencer

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Spencer Tickner <sp...@gmail.com>.
Thanks, Hassan,, that gives me a start.

On Dec 18, 2007 11:03 AM, Spencer Tickner <sp...@gmail.com> wrote:
> The files are "lost", as I'm firing the servlet in the
> {tomcat}\webapp\ServletDir\, that then reads a file "C:\somefile.htm"
> that in it has reference to <img src="test.gif", and test resides in
> C:\. somefile.htm is read and returned to the browser fine,, but the
> browser can't find test.gif.  Hope this clears up the confusion.
>
> Thanks
>
> Spencer
>
>
> On Dec 18, 2007 10:50 AM, Spencer Tickner <sp...@gmail.com> wrote:
> > Hi Hassan,
> >
> > Thanks for the response and sorry for the confusion.
> >
> > The Web-directory was badly named,, but I was refering to the
> > {tomcat}\webapp\ directory. When I was refering to Servlet Folder it
> > would be {tomcat}\webapp\ServletDir\
> >
> > Thanks,
> >
> > Spencer
> >
> >
> >
> > On Dec 18, 2007 10:42 AM, Hassan Schroeder <ha...@gmail.com> wrote:
> > > On Dec 18, 2007 9:56 AM, Spencer Tickner <sp...@gmail.com> wrote:
> > >
> > > > I've set up a security servlet that will check permissions on various
> > > > html, pdf, xml, etc, files.
> > >
> > > > 1) I started with the content files out of the Web directory all
> > > > together and kept the mapping in an xml file and then served them
> > > > using FileInputStream and writing them to the ServletOutputStream.
> > > > This doesn't work because any internal refrences (<img>, <style>,
> > > > etc.) are lost.
> > >
> > > "lost"? How so?
> > >
> > > > 2) My next attempt was to put them into the Servlet folder...
> > >
> > > I've no idea what you mean by "Web directory" or "Servlet folder";
> > > maybe you could describe more precisely how your webapp is
> > > currently configured.
> > >
> > > --
> > > Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> > >
> > > ---------------------------------------------------------------------
> > > To start a new topic, e-mail: users@tomcat.apache.org
> > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > >
> > >
> >
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Spencer Tickner <sp...@gmail.com>.
Hi Hassan and David,

Thanks, for the response. Hassan of course you're right, there are
always some standard for internal paths that have to be adhered to.
However with relative paths coming from editors that edit html their
documents can be seen exactly on the file system as they can be seen
on a web server such as apache or IIS. For other editors that just use
word documents the "Save As" HTML function packages all internal links
relatively so once again the internal links just work when deploying
on standard web-servers. They upload, no work from me ;).. Same goes
with a number of other technologies (InDesign, Framemaker). I think I
have come up with a solution though,, Redeploying my .war file was
overwriting all the files I had under it's webapps/servletname
directory. Seems to me if every time I re-deploy the war and copy the
WEB-INF folder into another folder webapps/mysites all files in
mysites remain intact and the servlet fires when accessing them (using
<url-pattern>/*</url-pattern>). I haven't tested it thoroughly but it
does seem to be working.

Thanks,

Spencer

On Dec 18, 2007 5:14 PM, David Smith <dn...@cornell.edu> wrote:
> Just by chance, could we see a sample url to one of your pages and a
> sample internal link?  It doesn't seem like this should be a big deal.
>
> --David
>
>
> Spencer Tickner wrote:
> > Hi Hassan,
> >
> >
> >
> > I wish I could establish a convention for internal links..
> > Unfortunately it's not possible as we get content from a diverse
> > editor base where our system may not be the primary delivery method.
> > Looking through our correspondence it would seem that I am trying to
> > address the problem when I should just be stating it.. My problem is
> > internal links are breaking in content served through my security
> > servlet. Thanks so much for the time and patience.. I do really
> > appreciate it.
> >
> > Spencer
> >
> > On Dec 18, 2007 3:33 PM, Hassan Schroeder <ha...@gmail.com> wrote:
> >
> >> On Dec 18, 2007 11:41 AM, Spencer Tickner <sp...@gmail.com> wrote:
> >>
> >>
> >>> Once again thanks for the feedback,, the issue I would have with the
> >>> solution above is that content (html, pdf, xml) is maintained by
> >>> editors that I have no control over. They simply make their content
> >>> look the way the want and then upload it to my application.
> >>>
> >> So you establish a convention for internal links; if they don't follow
> >> it, their stuff is broken. Not your problem then, eh? :-)
> >>
> >>
> >>> My app is responsible for controlling logging and accessing to these
> >>> documents (Administrators have an interface for granting access to
> >>> users on documents uploaded by the editor). I just can't seem to serve
> >>> these documents up.
> >>>
> >> Is the issue broken internal links, or what? I do this kind of thing on
> >> pretty much every site, so  I'm afraid I'm not understanding where the
> >> disconnect lies.
> >>
> >> --
> >>
> >> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> >>
> >> ---------------------------------------------------------------------
> >> To start a new topic, e-mail: users@tomcat.apache.org
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by David Smith <dn...@cornell.edu>.
Just by chance, could we see a sample url to one of your pages and a 
sample internal link?  It doesn't seem like this should be a big deal.

--David

Spencer Tickner wrote:
> Hi Hassan,      
>
>
>
> I wish I could establish a convention for internal links..
> Unfortunately it's not possible as we get content from a diverse
> editor base where our system may not be the primary delivery method.
> Looking through our correspondence it would seem that I am trying to
> address the problem when I should just be stating it.. My problem is
> internal links are breaking in content served through my security
> servlet. Thanks so much for the time and patience.. I do really
> appreciate it.
>
> Spencer
>
> On Dec 18, 2007 3:33 PM, Hassan Schroeder <ha...@gmail.com> wrote:
>   
>> On Dec 18, 2007 11:41 AM, Spencer Tickner <sp...@gmail.com> wrote:
>>
>>     
>>> Once again thanks for the feedback,, the issue I would have with the
>>> solution above is that content (html, pdf, xml) is maintained by
>>> editors that I have no control over. They simply make their content
>>> look the way the want and then upload it to my application.
>>>       
>> So you establish a convention for internal links; if they don't follow
>> it, their stuff is broken. Not your problem then, eh? :-)
>>
>>     
>>> My app is responsible for controlling logging and accessing to these
>>> documents (Administrators have an interface for granting access to
>>> users on documents uploaded by the editor). I just can't seem to serve
>>> these documents up.
>>>       
>> Is the issue broken internal links, or what? I do this kind of thing on
>> pretty much every site, so  I'm afraid I'm not understanding where the
>> disconnect lies.
>>
>> --
>>
>> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Hassan Schroeder <ha...@gmail.com>.
On Dec 18, 2007 4:45 PM, Spencer Tickner <sp...@gmail.com> wrote:

> I wish I could establish a convention for internal links..
> Unfortunately it's not possible as we get content from a diverse
> editor base where our system may not be the primary delivery method.

Then you're hosed, I think :-)

Seriously, if you can't define and enforce a standard for style, img
or whatever links, you'd have problems with static pages served up
straight from the file system.

Your content creators have to be aware of how the system is set up
and build valid documents for the deployment environment.

Or you have to post-process them. Or use a Filter to rewrite the bad
links on the fly, but as you point out those are both iffy :-)

I don't see where your security servlet even comes in to the picture.

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Spencer Tickner <sp...@gmail.com>.
Hi Hassan,

I wish I could establish a convention for internal links..
Unfortunately it's not possible as we get content from a diverse
editor base where our system may not be the primary delivery method.
Looking through our correspondence it would seem that I am trying to
address the problem when I should just be stating it.. My problem is
internal links are breaking in content served through my security
servlet. Thanks so much for the time and patience.. I do really
appreciate it.

Spencer

On Dec 18, 2007 3:33 PM, Hassan Schroeder <ha...@gmail.com> wrote:
> On Dec 18, 2007 11:41 AM, Spencer Tickner <sp...@gmail.com> wrote:
>
> > Once again thanks for the feedback,, the issue I would have with the
> > solution above is that content (html, pdf, xml) is maintained by
> > editors that I have no control over. They simply make their content
> > look the way the want and then upload it to my application.
>
> So you establish a convention for internal links; if they don't follow
> it, their stuff is broken. Not your problem then, eh? :-)
>
> > My app is responsible for controlling logging and accessing to these
> > documents (Administrators have an interface for granting access to
> > users on documents uploaded by the editor). I just can't seem to serve
> > these documents up.
>
> Is the issue broken internal links, or what? I do this kind of thing on
> pretty much every site, so  I'm afraid I'm not understanding where the
> disconnect lies.
>
> --
>
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Hassan Schroeder <ha...@gmail.com>.
On Dec 18, 2007 11:41 AM, Spencer Tickner <sp...@gmail.com> wrote:

> Once again thanks for the feedback,, the issue I would have with the
> solution above is that content (html, pdf, xml) is maintained by
> editors that I have no control over. They simply make their content
> look the way the want and then upload it to my application.

So you establish a convention for internal links; if they don't follow
it, their stuff is broken. Not your problem then, eh? :-)

> My app is responsible for controlling logging and accessing to these
> documents (Administrators have an interface for granting access to
> users on documents uploaded by the editor). I just can't seem to serve
> these documents up.

Is the issue broken internal links, or what? I do this kind of thing on
pretty much every site, so  I'm afraid I'm not understanding where the
disconnect lies.

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Spencer Tickner <sp...@gmail.com>.
Hi Hassan,

Once again thanks for the feedback,, the issue I would have with the
solution above is that content (html, pdf, xml) is maintained by
editors that I have no control over. They simply make their content
look the way the want and then upload it to my application. I could
feasibly search out all paths with html documents and do a little
replace magic on upload,, however this gets complicated to the point
of impossible when dealing with documents such as XML, XSLT where
internal references can be made with virtually unlimited semantics. So
keeping the directory structure the same from the "root down" is
important (Keeps a documents "form" in the responsibility sphere of
the editor).

My app is responsible for controlling logging and accessing to these
documents (Administrators have an interface for granting access to
users on documents uploaded by the editor). I just can't seem to serve
these documents up.

Thanks,

Spencer

On Dec 18, 2007 11:20 AM, Hassan Schroeder <ha...@gmail.com> wrote:
> On Dec 18, 2007 11:03 AM, Spencer Tickner <sp...@gmail.com> wrote:
> > The files are "lost", as I'm firing the servlet in the
> > {tomcat}\webapp\ServletDir\, that then reads a file "C:\somefile.htm"
> > that in it has reference to <img src="test.gif", and test resides in
> > C:\. somefile.htm is read and returned to the browser fine,, but the
> > browser can't find test.gif.  Hope this clears up the confusion.
>
> Then you need to use an absolute but context-relative path, e.g.
>
>    src="${pageContext.request.contextPath}/images/test.gif"
>
> (JSTL example) and put that image in
>
> $CATALINA_HOME/webapps/{appname}/images/
>
> HTH!
> --
>
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Hassan Schroeder <ha...@gmail.com>.
On Dec 18, 2007 11:03 AM, Spencer Tickner <sp...@gmail.com> wrote:
> The files are "lost", as I'm firing the servlet in the
> {tomcat}\webapp\ServletDir\, that then reads a file "C:\somefile.htm"
> that in it has reference to <img src="test.gif", and test resides in
> C:\. somefile.htm is read and returned to the browser fine,, but the
> browser can't find test.gif.  Hope this clears up the confusion.

Then you need to use an absolute but context-relative path, e.g.

   src="${pageContext.request.contextPath}/images/test.gif"

(JSTL example) and put that image in

$CATALINA_HOME/webapps/{appname}/images/

HTH!
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Spencer Tickner <sp...@gmail.com>.
The files are "lost", as I'm firing the servlet in the
{tomcat}\webapp\ServletDir\, that then reads a file "C:\somefile.htm"
that in it has reference to <img src="test.gif", and test resides in
C:\. somefile.htm is read and returned to the browser fine,, but the
browser can't find test.gif.  Hope this clears up the confusion.

Thanks

Spencer

On Dec 18, 2007 10:50 AM, Spencer Tickner <sp...@gmail.com> wrote:
> Hi Hassan,
>
> Thanks for the response and sorry for the confusion.
>
> The Web-directory was badly named,, but I was refering to the
> {tomcat}\webapp\ directory. When I was refering to Servlet Folder it
> would be {tomcat}\webapp\ServletDir\
>
> Thanks,
>
> Spencer
>
>
>
> On Dec 18, 2007 10:42 AM, Hassan Schroeder <ha...@gmail.com> wrote:
> > On Dec 18, 2007 9:56 AM, Spencer Tickner <sp...@gmail.com> wrote:
> >
> > > I've set up a security servlet that will check permissions on various
> > > html, pdf, xml, etc, files.
> >
> > > 1) I started with the content files out of the Web directory all
> > > together and kept the mapping in an xml file and then served them
> > > using FileInputStream and writing them to the ServletOutputStream.
> > > This doesn't work because any internal refrences (<img>, <style>,
> > > etc.) are lost.
> >
> > "lost"? How so?
> >
> > > 2) My next attempt was to put them into the Servlet folder...
> >
> > I've no idea what you mean by "Web directory" or "Servlet folder";
> > maybe you could describe more precisely how your webapp is
> > currently configured.
> >
> > --
> > Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Hassan Schroeder <ha...@gmail.com>.
On Dec 18, 2007 10:50 AM, Spencer Tickner <sp...@gmail.com> wrote:

> The Web-directory was badly named,, but I was refering to the
> {tomcat}\webapp\ directory. When I was refering to Servlet Folder it
> would be {tomcat}\webapp\ServletDir\

Have you read the Servlet Spec? I think it would give you a better
idea about how webapps are typically deployed :-)

Pages/documents you want to shield from direct access usually
go in WEB-INF, which is implicitly protected by the container. So
you might have something like

  $CATALINA_HOME/webapps/{appname}/WEB-INF/jsp
  $CATALINA_HOME/webapps/{appname}/WEB-INF/pdf

and servlets go in, e.g.

  $CATALINA_HOME/webapps/{appname}/WEB-INF/classes/com/example/whatever

> > > together and kept the mapping in an xml file and then served them
> > > using FileInputStream and writing them to the ServletOutputStream.
> > > This doesn't work because any internal refrences (<img>, <style>,
> > > etc.) are lost.
> >
> > "lost"? How so?

Still not clear on this problem, though...

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Spencer Tickner <sp...@gmail.com>.
Hi Hassan,

Thanks for the response and sorry for the confusion.

The Web-directory was badly named,, but I was refering to the
{tomcat}\webapp\ directory. When I was refering to Servlet Folder it
would be {tomcat}\webapp\ServletDir\

Thanks,

Spencer


On Dec 18, 2007 10:42 AM, Hassan Schroeder <ha...@gmail.com> wrote:
> On Dec 18, 2007 9:56 AM, Spencer Tickner <sp...@gmail.com> wrote:
>
> > I've set up a security servlet that will check permissions on various
> > html, pdf, xml, etc, files.
>
> > 1) I started with the content files out of the Web directory all
> > together and kept the mapping in an xml file and then served them
> > using FileInputStream and writing them to the ServletOutputStream.
> > This doesn't work because any internal refrences (<img>, <style>,
> > etc.) are lost.
>
> "lost"? How so?
>
> > 2) My next attempt was to put them into the Servlet folder...
>
> I've no idea what you mean by "Web directory" or "Servlet folder";
> maybe you could describe more precisely how your webapp is
> currently configured.
>
> --
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Servlet File Structure

Posted by Hassan Schroeder <ha...@gmail.com>.
On Dec 18, 2007 9:56 AM, Spencer Tickner <sp...@gmail.com> wrote:

> I've set up a security servlet that will check permissions on various
> html, pdf, xml, etc, files.

> 1) I started with the content files out of the Web directory all
> together and kept the mapping in an xml file and then served them
> using FileInputStream and writing them to the ServletOutputStream.
> This doesn't work because any internal refrences (<img>, <style>,
> etc.) are lost.

"lost"? How so?

> 2) My next attempt was to put them into the Servlet folder...

I've no idea what you mean by "Web directory" or "Servlet folder";
maybe you could describe more precisely how your webapp is
currently configured.

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org