解决方案 »

  1.   

    肯定要先存到SESSION里面呀,当他提交的时候你就再从SESSION里面与他输入的验证码进行对比呀!
      

  2.   

    另外一个Controller直接session.getAttribute("scode")获取验证码与输入对比!
      

  3.   


    Map<String,Object> result = new HashMap<String,Object>();
         //request.setCharacterEncoding("UTF-8");    
         String loginname = getRequest().getParameter("loginname");
         String loginpwd = getRequest().getParameter("password");
        
         //查看验证码
    String scode = (String) session.getAttribute("scode");
    System.out.println(scode);

         System.out.println(loginname);    
         System.out.println(loginpwd);
    我这个是有的,这个是输入的吧  怎么去获取它生成的那个验证码呢
      

  4.   

    <table style="text-align: center;">
         <tr><td colspan="2" style="height: 36px;"><span id="alert_msg" style="color: red"></span></td></tr>
         <tr><td style="text-align: right;width: 40%">用户名</td><td style="text-align: left;width: 60%"><input id="username" type="text" size="22" style="border: 1px solid #09c;"/></td></tr>
         <tr><td style="text-align: right;width: 40%">密码</td><td style="text-align: left;width: 60%"><input id="password" type="password" size="22" style="border: 1px solid #09c;" /></td></tr>
         <tr><td style="text-align: right;width: 40%">验证码</td><td style="text-align: left;width: 60%"> <input id="checkCode" type="text" size="10" style="border: 1px solid #09c;" /> <img style="width: 60px;height: 24px;vertical-align: middle;border: 1px solid #09c;padding: 0px;" src="http://www.tools138.com/checkCode.htm" onclick="this.src='http://www.tools138.com/checkCode.htm?' + new Date().getTime();" alt="点击更换"/> </td></tr>
         <tr><td colspan="2"><input style="margin-left: 200px;" type="button" value="登录" onclick="goSubmit();"/></td></tr>
         </table>参考下这个html ,checkcode.htm 这个是Action请求 ,验证的时候跟存在session里面的值进行对比
      

  5.   

    session.getAttribute("scode");  是获取生成的验证码
    request.getParameter("scode"); 这个才是获取页面输入的验证码参数一个是Session一个是request
      

  6.   


    谢谢你,我给你看下完整的登陆验证方法吧,不是我写的不太懂这些,你能帮忙看下怎么改吗public JsonView login(UserVO user) throws Exception{
         Map<String,Object> result = new HashMap<String,Object>();
         //request.setCharacterEncoding("UTF-8");    
         String loginname = getRequest().getParameter("loginname");
         String loginpwd = getRequest().getParameter("password");
        
         //查看验证码
    String scode = (String) session.getAttribute("scode");
    System.out.println(scode);

         System.out.println(loginname);    
         System.out.println(loginpwd);
         Map param=new HashMap();
         param.put("loginname", loginname);
         QueryParam qp=QueryParam.getInstance("from UserVO where loginname=:loginname",param);
         UserVO vo=(UserVO)this.getBasBS().queryOne(qp);
        
         if(!user.getCode().toUpperCase().equals(scode.toUpperCase())){
    //验证码错误
         result.put("code_error","验证码错误");
    result.put("failure",true);
    }
         if(vo==null){
         result.put("msg", "用户名称不存在!");
             result.put("failure", true);
         }else{
             if (vo.getState()==1){
              result.put("msg", "用户已禁用!");
                 result.put("failure", true);
             }
         if(MD5Util.md5(loginpwd).equals(vo.getPassword())){
         SessionInfo sessionInfo = new SessionInfo();
         sessionInfo.setId(vo.getId());
         sessionInfo.setName(vo.getName());
         sessionInfo.setLoginname(vo.getLoginname());
         sessionInfo.setOrgID(Long.parseLong(vo.getOrgid().toString()));
         sessionInfo.setUsertype(vo.getUsertype());
        
         //sessionInfo.setMenus(resourceBS.treeByIBatis(vo.getId(),null));
         sessionInfo.setResourceList(resourceBS.resourceListByIBatis(vo.getId()));
         session.setAttribute(GlobalConstant.SESSION_INFO, sessionInfo);
        
         result.put("success", true);  
             }else{
             result.put("failure", true);
             result.put("msg", "密码错误!");
             }
         }
         /*
         for(int i=0;i<list.size();i++){
         UserVO vo = (UserVO)list.get(i);
         System.out.println(vo.getOprid());
         System.out.println(vo.getOprname());
         }
         */
        
         /*
         Iterator it = list.iterator();
         while(it.hasNext()){
    UserVO vo = (UserVO)it.next();
    System.out.println(vo.getOprid());
         System.out.println(vo.getOprname());
    }*/
        
        
        
         JsonView v = new JsonView(result);
         v.setContentType("text/html;charset=utf-8");
         return  v;  //new JsonView(result);
        }
      

  7.   

    ·· 你是不是要把验证码生成图片?
    你生成图片的时候把验证码存入session
    然后把这个存入session的跟用户填写的对比不就行了吗!
      

  8.   

    每次生成新的验证码 都需要 进行一次set  set之前建议先清空   session.removeAttribute(attributeName);
      session.setAttribute("scode",“密码”);
      

  9.   


    我在jsp里怎么去显示图片呀?不用xml配置和注解
    function reloadcode()
           {

          var verify=document.getElementById('code');
              verify.setAttribute('src','getCode.jsp?it='+Math.random());
              window.location.href="${ctx}/sys/home/login";
           }
    <tr>
                        <td class="login_info" colspan="2">验证码:</td>
                        <td class="width70" ><input name="code" type="text" class="width70" /></td>
                        <td width="92"  style="text-align:center"><img alt="看不清楚,换一张" src="getCode.jsp" onclick="reloadcode();" id="code" style="position:relative;top:1px;left:0px;"></td>
                        
                    </tr>
      

  10.   

    <input name="code" type="text" class="width70" src="getCode.jsp" />src里面的这个可以填写你Controller的execute路径就可以了。
      

  11.   


    额,这貌似只是个输入框吧,我的完整路径是src="${ctx}/sys/GetCode/execute",其他页面调用方法都是可以的,路径应该没问题
      

  12.   


    额,这貌似只是个输入框吧,我的完整路径是src="${ctx}/sys/GetCode/execute",其他页面调用方法都是可以的,路径应该没问题
    不好意思,刚才弄错了;应该是这样写,把验证码显示出来!
    <img alt="看不清楚,换一张" src="${ctx}/sys/GetCode/execute" onclick="reloadcode();" id="code" style="position:relative;top:1px;left:0px;">
      

  13.   


    额,这貌似只是个输入框吧,我的完整路径是src="${ctx}/sys/GetCode/execute",其他页面调用方法都是可以的,路径应该没问题
    不好意思,刚才弄错了;应该是这样写,把验证码显示出来!
    <img alt="看不清楚,换一张" src="${ctx}/sys/GetCode/execute" onclick="reloadcode();" id="code" style="position:relative;top:1px;left:0px;">试过了。显示不出来,是我生成验证码的方式有问题吗