سؤال

I have a java servlet which sends a json response in order to fill a datatable.net, I need to generate the json response with some links.

I have the following piece of code:

LinkedList lt2 = new LinkedList();
lt2.add("<a href='host'>sasas</a>");
l1.add(lt2);
obj.put("aaData", l1);

The output

{"aaData":[
    ["1","Col2","Col3","Col4","Col5"],
    ["2","Col2","Col3","Col4","<a href='host'>sasas<\/a>"]
]
}

As you can see, the output cannot be interpreted by the browser like a link, I have tried to escape the characteres in different ways without get the desired output.

Is there anyway to do that? I prefer to server side processing.

هل كانت مفيدة؟

المحلول

I'm a ninja developer :D The hack is a bit trivial, I do a string replace in the followwing way:

lt2.add("<a href='host'>sasas</a>".replace("\\/", "/"));

So the content of the list now is represented like a link in the browser. Now, I wonder if there is a best way to do the same ...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top