I am looking to pass a string from my Java to a javascript showContent function. Both the Java and javascript are contained in a JSP page. The string strLine contains XML content I want to display using the showContent function.
My Java
try{
//Open the file that is the first command line parameter
FileInputStream fstream = new FileInputStream(table.get(xmlMatch));
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null)
{
out.println (strLine);
}
The Javascript (I have to credit Peter for supplying me with this in another question)
<script type="text/javascript" language="JavaScript">
function showContent()
{
document.getElementById('showContent').innerHTML = "printed content";
}
</script>
I have tried replacing the above "printed content" with "strLine"; (strLine); and ("strLine");
I also tried set strLine as a session attribute using
session.setAttribute("strLine", strLine); and using "<%=strLine%>"; but the result was null printed to the screen.
Any help with this would be great.
The HTML
<a href="#" onclick="showContent()">Next! <%=keywords%> concept </a>
<div id="showContent"></div>
strLineis 1 - 2 paragraphs of XML content. - ` out.println (strLine);` currently prints this to the page.<%=session.getAttribute("strLine")?>and not just<%=strLine%>(which refers to the original variable).