The example of this article describes the JSP combined with JS to implement the SRC update request in IMG method. Share to everyone for your reference. Specifically as follows:
1.javascript (Updated function)
<script type= "Text/javascript" >
function Changeimage () {
var img = document.getElementById ("Imgvcode") ;
if (img.name = = 1) {
img.name = 2;
IMG.SRC = "Shop.do?method=registerimage2";
} else if (Img.name = 2) {
img.name = 1;
IMG.SRC = "Shop.do?method=registerimage";
}
}
</script>
2.jsp img and IMG changed code
<td>
< Input name= "code" type= "text" id= "Txtverifycode" class= "Yzm_input" onblur= "Testcode"
(this)/>
class= "Text_left T1" >
<p class= "T1" >
<span id= "vcodevalidmsg" > Please enter four letters in the picture. </span>
<span id= "Codeinfo" style= "color:red" ></span>
<a href= "#" id= "Imgchange" Onclick= "Changeimage ()" > Can't see clearly? Change a picture </a>
</p>
</div>
</td>
3. Background Action Code
Public Actionforward registerimage (actionmapping mapping, actionform form,
httpservletrequest request, HttpServletResponse response)
throws Exception {
//Create image, return authentication code
response.setcontenttype ("Image/jpeg ");
OutputStream out = Response.getoutputstream ();
String strensure = Shopmanager.createimageinfo (50,20,out);
Set to session
Request.getsession (). setattribute ("Strensure", strensure);
return null;
}
Public Actionforward RegisterImage2 (actionmapping mapping, actionform form,
httpservletrequest request, HttpServletResponse response)
throws Exception {
//Create image, return authentication code
response.setcontenttype ("image/ JPEG ");
OutputStream out = Response.getoutputstream ();
String strensure = Shopmanager.createimageinfo (50,20,out);
Set to session
Request.getsession (). setattribute ("Strensure", strensure);
return null;
}
I hope this article will help you with your JavaScript programming.