开发者

A Rails' javascript_include_tag equivalent for Struts?

How can I emulate the javascript_include_tag (from Rails) for a Struts 1 application?

Something like:开发者_如何学C

<%= includeJS('jquery', 'application', 'blah1', 'blah2', ...) %>

In the JSP would be awesome.


You can obtain a similar result to Rails' javascript_include_tag by using a custom JSP tag (Struts has nothing similar but it is not that difficult to create one yourself).

A tag like the following should do the trick:

<my:includeJS sources="jquery, application, blah1, blah2" />

Your tag will have a string attribute (named sources in the example above) that receives a comma delimited list of script names. Once in your tag handler, you split the names by the comma and use them to create the HTML <script> tags:

....
<script type="text/javascript" src="/javascripts/blah1.js"></script>
<script type="text/javascript" src="/javascripts/blah2.js"></script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜