JavaからjavascriptshowContent関数に文字列を渡そうとしています。Javaとjavascriptの両方がJSPページに含まれています。文字列strLine
には、showContent関数を使用して表示するXMLコンテンツが含まれています。
私の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);
}
Javascript(別の質問でこれを提供してくれたPeterの功績を認めなければなりません)
<script type="text/javascript" language="JavaScript">
function showContent()
{
document.getElementById('showContent').innerHTML = "printed content";
}
</script>
上記の「印刷物」をとに置き換えてみまし"strLine";
(strLine);
た("strLine");
また、を使用しstrLine
てセッション属性として
設定しようとしましたが、結果が画面にnullで出力されました。session.setAttribute("strLine", strLine);
"<%=strLine%>";
これに関するどんな助けも素晴らしいでしょう。
HTML
<a href="#" onclick="showContent()">Next! <%=keywords%> concept </a>
<div id="showContent"></div>