如何使用JQuery在JSP中附加java代码

时间:2022-10-16 00:13:10

I am working with JSP pages and I need to .append() into a DIV element some java codes.

我正在使用JSP页面,我需要将.append()转换为一些Java代码的DIV元素。

$("#myDiv").append("<% out.println("ali"); %>");

The previous code is actually wrong because there's quotes, so I escaped them.

之前的代码实际上是错误的,因为有引号,所以我逃脱了它们。

$("#myDiv").append("<% out.println(\"ali\"); %>");

But I wasn't successful, nothing was appended to #myDiv

但我没有成功,没有任何内容被附加到#myDiv

3 个解决方案

#1


0  

This is correct way to append. If nothing is appended, then the div might not exists in the page.

这是追加的正确方法。如果没有附加任何内容,则页面中可能不存在div。

Try using firebug and check what6 is the output of console.log($('#muDiv'))

尝试使用firebug并检查what6是console.log的输出($('#muDiv'))

#2


0  

Your code should work, it sounds that jQuery is not loaded correctly or there is another problem.

你的代码应该工作,听起来jQuery没有正确加载或有另一个问题。

http://jsfiddle.net/5PTwN/1/

#3


0  

Try this

$("#myDiv").append('<% out.print("ali"); %>');

below line also should work because java code will execute server side and inside append will be replaced with "ali".

下面的行也应该工作,因为java代码将执行服务器端,内部追加将替换为“ali”。

$("#myDiv").append("<% out.print("ali"); %>");

#1


0  

This is correct way to append. If nothing is appended, then the div might not exists in the page.

这是追加的正确方法。如果没有附加任何内容,则页面中可能不存在div。

Try using firebug and check what6 is the output of console.log($('#muDiv'))

尝试使用firebug并检查what6是console.log的输出($('#muDiv'))

#2


0  

Your code should work, it sounds that jQuery is not loaded correctly or there is another problem.

你的代码应该工作,听起来jQuery没有正确加载或有另一个问题。

http://jsfiddle.net/5PTwN/1/

#3


0  

Try this

$("#myDiv").append('<% out.print("ali"); %>');

below line also should work because java code will execute server side and inside append will be replaced with "ali".

下面的行也应该工作,因为java代码将执行服务器端,内部追加将替换为“ali”。

$("#myDiv").append("<% out.print("ali"); %>");