是否可以使用JSP / JSTL来生成动态css / javascript文件? [英] Is it possible to use JSP/JSTL to generate dynamic css/javascript files?

查看:259
本文介绍了是否可以使用JSP / JSTL来生成动态css / javascript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



不嵌入js / css而是一个实际文件...

解决方案

你想做的是分配* .css servlet映射



在大多数容器中,您将看到类似这样的映射(这来自Glassfish,在它的default-web.xml中):

 < servlet> 
< servlet-name> jsp< / servlet-name>
< servlet-class> org.apache.jasper.servlet.JspServlet< / servlet-class>
< init-param>
< param-name> xpoweredBy< / param-name>
< param-value> true< / param-value>
< / init-param>
< load-on-startup> 3< / load-on-startup>
< / servlet>
< servlet-mapping>
< servlet-name> jsp< / servlet-name>
< url-pattern> *。jsp< / url-pattern>
< / servlet-mapping>

在这里,它声明了JSP servlet,并将* .jsp映射到它。因此,在这种情况下,JSP servlet引用名称只是'jsp'。



因此,您需要添加:

 < servlet-mapping> 
< servlet-name> jsp< / servlet-name>
< url-pattern> *。css< / url-pattern>
< / servlet-mapping>

当你这样做时,突然所有的CSS文件都是有效的JSP,



细节是我不知道'jsp'对于所有容器是否相同,所以你的web.xml可能不是便携式。



但这是你想做的事情的要点。如果你不想让所有的CSS都是JSP,你可以把这些文件放在自己的目录中,并把它映射到JSP servlet。然后任何你放在那里会有一个JSP(css,js等)


If so how do you do this?

(jboss/tomact embedded/jdk 1.5)

not embedded js/css but an actual file...

解决方案

What you want to do is assign the *.css servlet mapping to the JSPServlet.

In most containers, you will see a mapping like this (this is from Glassfish, in it's default-web.xml):

  <servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
      <param-name>xpoweredBy</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>

Here, it is declaring the JSP servlet, and mapping "*.jsp" to it. So, in this case, the JSP servlet reference name is, simply 'jsp'.

So you would want to add:

<servlet-mapping>
  <servlet-name>jsp</servlet-name>
  <url-pattern>*.css</url-pattern>
</servlet-mapping>

When you do that, "suddenly" ALL of your CSS files are, effectively, JSPs, so you can do with them whatever you want.

The detail is I don't know if 'jsp' is the same for ALL containers, so your web.xml MAY NOT be portable.

But that's the gist of what you want to do. If you don't want ALL CSS to be JSPs, you could put the files in their own directory, and map that to the JSP servlet. Then ANYTHING you put in there would be a JSP (css, js, etc.)

这篇关于是否可以使用JSP / JSTL来生成动态css / javascript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆