简体   繁体   English

从String变量渲染CSS文件。

[英]Rendering CSS file from String variable.

Is it possible to render a css file from a string data that i found from my controller class? 是否可以根据我从控制器类中找到的字符串数据来呈现CSS文件? I have a jsp page, and the page will try to get a css varilable like this: 我有一个jsp页面,并且该页面将尝试获取如下的CSS变量:

 <link rel="stylesheet" type="text/css" href="/Style/css=${css}" /> 

Style is the method on the controller class that returns css string variable. 样式是控制器类上返回css字符串变量的方法。 Simply the Style method returns a string. 只需使用Style方法即可返回一个字符串。 I have it on jsp. 我在jsp上有它。 But i couldn't render it as a css file, it just returns it on the page. 但是我无法将其呈现为CSS文件,它只是在页面上将其返回。 Is there any way to render that string as a css file. 有什么方法可以将该字符串呈现为css文件。

Nope, you can't do that. 不,你不能那样做。 Easiet solution: 简便的解决方案:

<style type="text/css"> ${css} </style>

Otherwise you have to create new file with contents of ${css} variable and than include it in html with <link> tag. 否则,您必须使用${css}变量的内容创建新文件,然后使用<link>标记将其包含在html中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有小胡子的Spring MVC发送字符串变量。 - Spring MVC with Moustache sending a string variable. Javascript 中的数字在声明为变量后会发生变化。 即使从字符串中解析它也会返回错误的数字 - Number in Javascript changes after declaring it as a variable. Even parsing it from a string returns a wrong number 需要将用户输入从提示框(Javascript)放入String变量。 我该怎么做? - Need to place user input from a prompt box (Javascript) into a String variable. How do I do so? 将字符串内的 &#39; 和 &quot; 转换为在变量内使用。(Javascript) - Convert ' and " inside a string to be used inside a variable. (Javascript) 从函数外部访问变量并返回该变量。 在模块模式中 - accessing a variable from outside a function and returning the variable. In a module pattern 如何将上传的 pdf 文件传递​​给变量。 (PDF.JS) - How to pass uploaded pdf file to the variable. (PDF.JS) Javascript从变量获取IMG src。 SharePoint内容搜索 - Javascript get IMG src from variable. SharePoint Content Search 从对象变量获取值有问题。 没有错误显示 - Having issue with getting value from object variable. No errors showing 根据订阅的变量应用 CSS 属性。 暗模式与亮模式 - Applying CSS properties based on subscribed variable. Dark mode vs light 将条件存储为变量。 使用Javascript - Store a condition as a variable. Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM