在 firefox、chrome 中处理像 css 这样的 jsp 时出现问题
我正在编写一个可供多个组织使用的 Web 应用程序,该应用程序需要根据使用我的页面的客户来自定义样式(该页面针对不同的公司进行“品牌化”)。
基本上,我有一个数据库,其中存储一些信息,例如原色、背景颜色和公司徽标图像,所有这些信息都根据谁使用我的网站而有所不同。
当有人访问我的网站时,我会查找他们的样式信息并将其作为名为“brand”的参数放入会话范围中,
我有一个名为brandCss.jsp 的jsp,它执行以下操作:
#logo
{
background-image: url( '${brand.logoImage}' );
}
body
{
color: ${brand.primaryColor};
}
等等
。我页面的 head> 标记,我链接到我的 JSP 就像它是一个 css 文件:
<link type="text/css" href="/brandCss" rel="stylesheet"/>
使用 spring 框架,我将对 /brandCss 的请求映射到我的brandCss.jsp 视图,这样这个请求就会将我的 JSP 作为视图返回。
这在 IE 中效果很好——有人点击我的页面,我的服务器代码就会启动并找到他们需要查看的品牌(样式)信息,然后将其放入我的 JSP 中,然后将其视为 css 文件。
然而,在 Firefox/Chrome 中,我的brandCss.jsp 样式表没有被使用——我的页面正确地下拉了jsp,并且它获得了与IE 完全相同的信息,但由于某种原因,浏览器选择忽略其中的样式。
有人知道为什么会这样或者如何让 Firefox 将我的 JSP 视为 css 吗?
I am writing a web application for use by multiple organizations which requires custom styling depending on which customer is using my page (the page is "branded" for different companies).
Basically, I have a database which stores some information such as primary color, background color, and company logo image, all of which vary depending on who is using my site.
When someone comes to my site, I look up their styling information and put it in session scope as a parameter named "brand"
I have a jsp called brandCss.jsp which does things such as:
#logo
{
background-image: url( '${brand.logoImage}' );
}
body
{
color: ${brand.primaryColor};
}
etc.
Then in the <head>
tag of my page, I link to my JSP as if it were a css file:
<link type="text/css" href="/brandCss" rel="stylesheet"/>
Using the spring framework, I map a request for /brandCss to my brandCss.jsp view, so that this request returns my JSP as a view.
This works great in IE--someone hits my page and my server code goes off and finds the branding (styling) information they need to see, then splats it into my JSP which is then treated as a css file.
However, in Firefox/Chrome, my brandCss.jsp stylesheet is not used--my page IS pulling down the jsp correctly, and it gets exactly the same information as IE, but for some reason the browser chooses to ignore the styling in it.
Anyone have any idea why this or how to make Firefox treat my JSP like css?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保您的页面将 Content-Type 设置为
text/css
。如果页面没有提供正确的 Content-Type,我怀疑 Firefox 会忽略它。借助 Firebug 之类的工具可以轻松检查这一点(请参阅“网络”选项卡以获取所请求的文件)。我不太确定您将如何在 Spring 中或从 Java Web 应用程序中设置
Content-Type
,但这就是我首先要检查的内容。Make sure your page is setting the Content-Type to
text/css
. If the page isn't being served with the correct Content-Type, I would suspect Firefox would ignore it. This is easy to check with the help of something like the Firebug (see the Net tab for the files that are requested).I'm not exactly sure how you would go about setting the
Content-Type
in Spring, or from a Java web app, but that is what I would check first.