The moose likes Struts and the fly likes Is stylesheet not visible to Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Is stylesheet not visible to Struts" Watch "Is stylesheet not visible to Struts" New topic

Is stylesheet not visible to Struts

PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 186
My struts project uses a template. I also have a style sheet. I want the design in the style sheet to be in each jsp pages that are displayed to the user. Somehow it is not working now. Does anybody now why? I use WSAD for development. My template.jsp is given below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ page
contentType="text/html; charset=ISO-8859-1"

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="../theme/Master.css" rel="stylesheet" type="text/css">

<title><template:get name='title'/></title>

<template:get name='header'/>
<template:get name='content'/>
<template:get name='footer'/>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, let's make one thing clear: This has absolutely nothing to do with Struts. A Struts JSP picks up a CSS just the same way any other JSP does.

One thing you have to realize about developing in WSAD:

The "base context path" used by the page desinger tool may not match the path for the page when it is being displayed on the server. Consequently, sometimes the page won't pick up the CSS in Page Designer, but it will on the server and visa versa.

There are a couple of options:

1- Put a <html:base /> tag at the beginning of your page. This indicates that all paths used on the page are relative to the JSP page itself.

2-Use a scriptlet to get the context path like this:
<LINK href="<%=request.getContextPath()%>/theme/Master.css" rel="stylesheet" type="text/css">
The good news is this will cause the CSS to always be found on the server. The bad news is that it will never be found in WSAD Page Designer.

Consultant, Sima Solutions
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 186
Great! It started working after putting the <html:base /> tag.
PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 186
Actually either of this tricks works.
Thank you.
I agree. Here's the link:
subject: Is stylesheet not visible to Struts
It's not a secret anymore!