画像を表示したり、オーディオ (CAPTCHA) を再生したりできるという要件があります。画像とオーディオの周りに div タグを追加し、ハイパーリンクをクリックすると、div の表示が変更されますが、変更 (div) が失われると失われます。ページが再表示されます。
使用技術: Java、JSP、javascript
があります
a) 画像を
表示する (デフォルト) またはb) 要求されたときにオーディオを再生する
画像と音声の両方の「src」はサーブレットです。
<tr> <td> </td> <td> <div id="audioPlayerContainer" style="display:none"> </div> </td> </tr> <tr> <td> </td> <td><div id="imageContainer"> <img src='MyServlet?mode=image&ts=<%=Math.random()%>' width="100" height="100"/> </div> </td> </tr>
画像または音声の要求を切り替えるためのリンクが存在する jsp のセクション
<a href="#" onclick="switchMode('audio');">Play audio</a> // OR <a href="#" onclick="switchMode('image');> Show image</a>
リンクのクリック時の JavaScript
function switchMode(modeType){ if (modeType=="audio"){ var uri = '/MyServlet?mode=audio&ts='+new Date().getTime(); document.getElementById('audioPlayerContainer').style.display ="block"; document.getElementById('imageContainer').style.display ="none"; //logic to determine the browser type and browser verion- embed tag or audio document.getElementById("audioPlayerContainer").innerHTML= "<embed src='"+uri+"' autostart='true' loop='false' height='100' width='100'/>"; }else if (modeType=="image"){ document.getElementById("audioPlayerContainer").style.display = "none"; document.getElementById('imageContainer').style.display ="block"; } //page to reload with updated divs //window.location.href=window.location.href; //window.location.reload(0); //Both reloads page, state of div tags comes bck to default //document.forms[0].submit();//this doesnt even seem to work }
`