JSP combining JS to implement the method of SRC update request in IMG _jsp programming

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.