我有一个表单,我已经实现Simple captcha每件事情都运行正常,但我希望在用户点击播放按钮时播放音频验证码。在我的情况下,音频在页面加载时默认播放。
以下是我的音频验证码
public class MyAudioCaptcha extends AudioCaptchaServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
MyTextProducer myTextProducer = (MyTextProducer) req.getSession().getAttribute("myTextProducer");
if(myTextProducer == null){
myTextProducer = new MyTextProducer();
}
AudioCaptcha ac = new AudioCaptcha.Builder().
addAnswer(myTextProducer).
addNoise().
build(); // Required
CaptchaServletUtil.writeAudio(resp, ac.getChallenge());
req.getSession().setAttribute("audioCaptcha", ac);
} catch (Exception e) {
Util.AppendExceptionToLog(e);
}
}
}
JSP代码:
<script>
$(document).ready(function(){
reloadCaptcha();
});
function reloadCaptcha(){
var d = new Date();
$.ajax({
url:"captcha.jsp",
type :"POST",
async:true,
data: {
'action': 'generateCaptcha' ,
},
success:function(response){
$("#captcha_image").attr("src", "../../simpleCaptcha.png?"+d.getTime());
$("#captcha_audio").attr("src", "../../audio.wav?"+d.getTime());
},
});
}
</script>
<body>
<td>
<div class="inputfield" style="margin-left: 10px;">
<img id="captcha_image" />
<img src="../../images/reload.jpg" onclick="reloadCaptcha()" style="cursor: pointer;" alt="reload"width="30" height="30"/>
</div>
</td>
<td>
<audio controls autoplay id="captcha_audio" autoplay = "false"></audio>
</td>
</body>
答案 0 :(得分:0)
您在autoplay
标记中配置了autoplay = "faluse"
和<audio>
,您应将其删除。
autoplay属性是一个布尔属性。
如果存在,音频将在不停止的情况下立即自动开始播放。