You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wendy Smoak <We...@asu.edu> on 2002/11/15 03:26:59 UTC

stylesheets with jsp's under WEB-INF?

I asked about this on comp.lang.java.programmer, and the response was,
basically, "Don't do that."  So, since Struts is the reason I'm putting my
jsp's under WEB-INF, can anyone here help with this dilemma?

Would it be better to move the jsp's back above WEB-INF and put in a Filter
to stop people accessing them directly?  (Not quite sure _how_ yet but if
that's the answer I'll figure it out!)

[Tomcat 4.1.14, Struts 1.1 nightly]

I can't get my jsp's that are stored under WEB-INF/jsp to "see" my
stylesheet.

The jsp lives in:
/path/to/tomcat/webapps/dev/WEB-INF/jsp/contact.jsp
(They are under WEB-INF to keep people from getting to them without going
through the Struts action controller.)

I don't really need to hide my stylesheet, so it can live in:
/path/to/tomcat/webapps/dev/css/style.css

With all the style stuff directly in the jsp, it was working fine. But since
I want to use this stylesheet with all of my jsp's, I'd like to store it
separately.
I've tried both:
<LINK REL="stylesheet" TYPE="text/css" HREF="css/style.css" TITLE="Style" />
<LINK REL="stylesheet" TYPE="text/css" HREF="/css/style.css" TITLE="Style"/>

As well as putting style.css right beside contact.jsp and using
HREF="style.css"

I'm sure I just haven't hit on the right combination of where to put it and
what LINK tag to use. Can someone enlighten me?

Thanks in advance,

--
Wendy in Chander, AZ



RE: stylesheets with jsp's under WEB-INF?

Posted by James Mitchell <jm...@telocity.com>.
Hi Wendy,

I understand your dilemma.  I typically use a stylesheet tag that I wrote
about a year ago to solve this.

While there are a couple of ways to handle this, I find this the cleanest.

 The sourceforge.net site is down for maintenance right now, but the cvs
viewer is working:
 http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/struts/struts-atlanta/

You can find the tld and the source there.

It allows you to do this:
 <util:styleSheet href="/stylesheets/struts-atlanta.css"/>

and it will prepend your application prefix.



James Mitchell
Software Engineer/Struts Evangelist
http://www.open-tools.org

"If you were plowing a field, which would you rather use? Two strong oxen or
1024 chickens?"
- Seymour Cray (1925-1996), father of supercomputing


> -----Original Message-----
> From: Wendy Smoak [mailto:Wendy.Smoak@asu.edu]
> Sent: Thursday, November 14, 2002 9:27 PM
> To: struts-user@jakarta.apache.org
> Subject: stylesheets with jsp's under WEB-INF?
>
>
>
> I asked about this on comp.lang.java.programmer, and the response was,
> basically, "Don't do that."  So, since Struts is the reason I'm putting my
> jsp's under WEB-INF, can anyone here help with this dilemma?
>
> Would it be better to move the jsp's back above WEB-INF and put
> in a Filter
> to stop people accessing them directly?  (Not quite sure _how_ yet but if
> that's the answer I'll figure it out!)
>
> [Tomcat 4.1.14, Struts 1.1 nightly]
>
> I can't get my jsp's that are stored under WEB-INF/jsp to "see" my
> stylesheet.
>
> The jsp lives in:
> /path/to/tomcat/webapps/dev/WEB-INF/jsp/contact.jsp
> (They are under WEB-INF to keep people from getting to them without going
> through the Struts action controller.)
>
> I don't really need to hide my stylesheet, so it can live in:
> /path/to/tomcat/webapps/dev/css/style.css
>
> With all the style stuff directly in the jsp, it was working
> fine. But since
> I want to use this stylesheet with all of my jsp's, I'd like to store it
> separately.
> I've tried both:
> <LINK REL="stylesheet" TYPE="text/css" HREF="css/style.css"
> TITLE="Style" />
> <LINK REL="stylesheet" TYPE="text/css" HREF="/css/style.css"
> TITLE="Style"/>
>
> As well as putting style.css right beside contact.jsp and using
> HREF="style.css"
>
> I'm sure I just haven't hit on the right combination of where to
> put it and
> what LINK tag to use. Can someone enlighten me?
>
> Thanks in advance,
>
> --
> Wendy in Chander, AZ
>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: stylesheets with jsp's under WEB-INF?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Thu, 14 Nov 2002, Wendy Smoak wrote:

> Date: Thu, 14 Nov 2002 19:26:59 -0700
> From: Wendy Smoak <We...@asu.edu>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: struts-user@jakarta.apache.org
> Subject: stylesheets with jsp's under WEB-INF?
>
>
> I asked about this on comp.lang.java.programmer, and the response was,
> basically, "Don't do that."  So, since Struts is the reason I'm putting my
> jsp's under WEB-INF, can anyone here help with this dilemma?
>
> Would it be better to move the jsp's back above WEB-INF and put in a Filter
> to stop people accessing them directly?  (Not quite sure _how_ yet but if
> that's the answer I'll figure it out!)
>
> [Tomcat 4.1.14, Struts 1.1 nightly]
>
> I can't get my jsp's that are stored under WEB-INF/jsp to "see" my
> stylesheet.
>
> The jsp lives in:
> /path/to/tomcat/webapps/dev/WEB-INF/jsp/contact.jsp
> (They are under WEB-INF to keep people from getting to them without going
> through the Struts action controller.)
>
> I don't really need to hide my stylesheet, so it can live in:
> /path/to/tomcat/webapps/dev/css/style.css
>
> With all the style stuff directly in the jsp, it was working fine. But since
> I want to use this stylesheet with all of my jsp's, I'd like to store it
> separately.
> I've tried both:
> <LINK REL="stylesheet" TYPE="text/css" HREF="css/style.css" TITLE="Style" />
> <LINK REL="stylesheet" TYPE="text/css" HREF="/css/style.css" TITLE="Style"/>
>
> As well as putting style.css right beside contact.jsp and using
> HREF="style.css"
>
> I'm sure I just haven't hit on the right combination of where to put it and
> what LINK tag to use. Can someone enlighten me?
>

The fundamental issue you are running into is the fact that the servlet
spec prohibits serving any resource under /WEB-INF to the client directly
-- which, of course, is why you're putting the JSP page there in the first
place.  But, if you think for a second about what really happens when you
create a link to the stylesheet, you'll realize that the *client* is going
to grab it with a separate request -- and, if that path points inside the
/WEB-INF directory, it's going to fail!

You're perfectly free to leave your stylesheet where it is (in the "css"
subdirectory under your webapp), as long as you use an appropriate
relative URL:

  <LINK REL="stylesheet" TYPE="text/css" HREF="../../css/style.css" TITLE="style" />

This will get resolved (by the client) to an absolute URL that is outside
the WEB-INF directory, so everything should work normally.

NOTE -- the exact same issue will apply to any <img> element in your JSP
page where you're trying to use a relative URL to an image in the same
directory.  That fails for the same reason as retrieving the stylesheet
fails, because the image is retrieved by the client with a separate
request.

> Thanks in advance,
>
> --
> Wendy in Chander, AZ
>
>
>

Craig



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>