`
Listen_ing
  • 浏览: 36718 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

验证码相关2

阅读更多
登录的jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
       <title>用户登录</title>


       <script type="text/javascript">  
     function changeValidateCode(obj) {  
            //获取当前的时间作为参数,无具体意义  
         var timenow = new Date().getTime();  
            //每次请求需要一个不同的参数,否则可能会返回同样的验证码  
         //这和浏览器的缓存机制有关系,也可以把页面设置为不缓存,这样就不用这个参数了。  
         obj.src="rand.action?d="+timenow;  
     }  
</script>


    </head>


    <body >
       <s:form action="LoginUser" method="post" namespace="/user" theme="simple">
           <table border="1" bordercolor="red">
              <tr>
                  <td>
                     用户名:
                     <s:textfield name="user.username"></s:textfield>
                  </td>
              </tr>
              <tr>
                  <td>
                     密码:
                     <s:password name="user.password"></s:password>
                  </td>
              </tr>
              <tr><td>
              <s:property value="random"/>
              :</td>
              <td>
              <s:textfield name="rand" size="5"></s:textfield>
              <s:fielderror><s:param>rand</s:param></s:fielderror>
              <img  src="rand.action" onclick="changeValidateCode(this)"
                  title="点击图片刷新验证码" />
                  </td></tr>
              <tr>
                  <td>
                     <s:submit value="登录"></s:submit>
                     &nbsp;
                     <s:reset value="取消"></s:reset>
                  </td>
              </tr>
           </table>


       </s:form>
    </body>
</html>


生成验证码打action配置文件:

<action name="rand" class="Rand">
           <result name="success" type="stream">
             <param name="contentType">image/jpeg</param> 
                <param name="inputName">inputStream</param>
                </result>
                <interceptor-ref name="defaultStack"></interceptor-ref>
       </action>
因为加了全局拦截器,所以要再此加上默认拦截器。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics