wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Is stylesheet not visible to Struts" Watch "Is stylesheet not visible to Struts" New topic
Author

Is stylesheet not visible to Struts

PradeepPillai Pradeep
Ranch Hand

Joined: Nov 15, 2005
Posts: 184
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">

<html>
<head>
<%@ 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
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="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>
</head>

<body>
<p>
<template:get name='header'/>
<template:get name='content'/>
<template:get name='footer'/>
</body>
</html>
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.


Merrill
Consultant, Sima Solutions
PradeepPillai Pradeep
Ranch Hand

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

Joined: Nov 15, 2005
Posts: 184
Actually either of this tricks works.
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is stylesheet not visible to Struts
 
Similar Threads
struts tags on tomcat server
including content in jsp from action class ?
Struts tag lib problem on tomcat 4.1.29
Struts Tag inside a Custom Tag
JSF page Declarations