开发者

Can JSP tags be used in JavaScript?

I'm building some HTML in JavaScript to be passed back to a JSP and I was doing this:

var html = "<td id='comm开发者_JAVA技巧ent-" + comment.id + "'class='wrappable' style='width:400px;'>"
    + "<pre style='width: auto;'>" + comment.comment + "</pre></td>";

But I found some JSP tag to use as an alternative to using <pre> to solve my newLine problem:

var html = "<td id='comment-" + comment.id + "'class='wrappable' style='width:400px;'>"
    + "<ctl:breakNewline target='" + comment.comment + "'/></td>";

But it doesn't seem to work. How is this caused and how can I solve this properly?


JSP is evaluates on the server, JavaScript on the client. No, this can't work.

(Of course you can use JSTL to create your entire JavaScript code, but you can't call JSP code from javaScript)


Without ever having used JSP or JSTL I'm going to take a wild guess at this and say: No.

As far as i know, JSP is server-side only, and unless you're running this html generating code on the server (rather than in browser/client-side), with some javascript parser on the server before passing it to the JSP parser, this will not work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜