I m using a css file with tiles but it is not working.
my tiles.xml is:
<tiles-definitions>
<definition name="baseLayout" template="/jsps/mail/mailbase.jsp">
<put-attribute name="css" value="/css/mail.css" type="string" />
<put-attribute name="menu" value="/jsps/mail/menu.jsp"/>
<put-attribute name="body" value=""/>
</definition>
<definition name="inbox.tile" extends="baseLayout">
<put-attribute name="css" value="/css/mail.css" type="string" />
<put-attribute name="body" value="/jsps/mail/inbox.jsp"/>
</definition>
<definition name="msgdetail.tile" extends="baseLayout">
<put-attribute name="body" value="/jsps/mail/msgDetails.jsp"/>
</definition>
<definition name="compose.tile" extends="baseLayout">
<put-attribute name="body" value="/jsps/mail/compose.jsp"/>
</definition>
<definit开发者_如何转开发ion name="msgsent.tile" extends="baseLayout">
<put-attribute name="body" value="/jsps/mail/msg_sent.html"/>
</definition>
</tiles-definitions>
and my jsp is:
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
**<link type="text/css" rel="stylesheet" href="<tiles:getAsString name='css'/>"/>**
</head>
<body>
<div id="left"><tiles:insertAttribute name="menu"/></div>
<div id="right"><tiles:insertAttribute name="body"/></div>
</body>
</html>
My CSS file "mail.css" lies in tomcat_root/web-app-name/css/mail.css
and jsp is in tomcat_root/web-app-name/jsps/mailbase.jsp
control flow is like:
request---------->inboxaction(struts2.xml)------------------>inbox.tile (tiles.xml)
The line
<link type="text/css" rel="stylesheet" href="<tiles:getAsString name='css'/>"/>
will be translated to
<link type="text/css" rel="stylesheet" href="/css/mail.css"/>
But your CSS file is at /web-app-name/css/mail.css
.
You should always use <c:url>
to generate URLs:
<tiles:useAttribute id="relativeCssUrl" name="css"/>
<c:url var="absoluteCssUrl" value="${relativeCssUrl}"/>
<link type="text/css" rel="stylesheet" href="${absoluteCssUrl}"/>
Or you might also use
<link type="text/css" rel="stylesheet" href="${request.contextPath}/<tiles:getAsString name='css'/>"/>
精彩评论