问题
I'm working with struts 2. In my JSP I have a <s:head />
tag. Somhow this triggers this css links to be inserted into the final HTML file:
<link href="/app/styles/design.css" rel="stylesheet" type="text/css" media="all"/>
<link href="/app/styles/print.css" rel="stylesheet" type="text/css" media="print"/>
<link rel="stylesheet" href="css/flick/jquery-ui-1.10.0.xyz.min.css" />
How does struts know about this files? How can I add other CSS files or change them?
回答1:
Struts UI tags generate HTML content via executing freemarker templates. The default templates are found in the core package under the /template
folder. The default template for the head
tag is head.ftl
.
There are several files one per theme. Corresponding template is used by selecting a theme for your tag, page, or application. See more about Selecting Themes.
If you want to change some templates you need to create a template folder and specify it as templateDir
. Then copy/paste your head.ftl
to this folder under the corresponding theme, e.g. /template/xhtml/head.ftl
. Now, when template is loading it will search this folder for the template overridden by you.
Another solution is possible to by extending an existed theme. You can choose whatever applicable to you.
回答2:
This was a nasty one. After all I discovered that the application is using sitemesh and uses the <s:head>
tag in the final jsp. This means the first 3 CSS files are comming fromt the sitemesh template, the struts/xhtml/styles.css
is comming from the xhtml fremarker template.
来源:https://stackoverflow.com/questions/23609303/how-is-struts-finding-css-files