获取验证码代码怎么写

获取验证码代码怎么写,第1张

问题一:jsp中显示验证码代码怎么写? import javaawtColor;import javaawtFont;import javaawtGraphics;import javaawtimageBufferedImage;import javaioIOException;import javaioOutputStream;import javautilRandom;import javaximageioImageIO;/生成验证码/public class MakeCertPic { 验证码中可以出现的字符集,可以根据需要修改 private char mapTable[]={ 'a','b','c','d','e','f', 'g','h','i','j','k','l', 'm','n','o','p','q','r', 's','t','u','v','w','x', 'y','z','0','1','2','3', '4','5','6','7','8','9' };/ 功能:生成彩色验证码 参数wedth为生成的宽度,参数height为生成的高度,参数os为页面的输出流/ public String getCertPic(int width,int height,OutputStream os){ if(width>

问题二:验证码的html怎么写 JS生成验证码code {background-image: url(codejpg);font-family: Arial;font-style: italic;color: Red;border: 0;padding: 2px 3px;letter-spacing: 3px;font-weight: bolder;}unchanged {border: 0;} var code; 在全局 定义验证码 function createCode() { code = ; var codeLength = 6;验证码的长度 var checkCode = documentgetElementById(checkCode); var selectChar = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');所有候选组成验证码的字符,当然也可以用中文的 for (var i = 0; i >

问题三:获取到了手机验证码的代码怎么写 按照验证码写上去

问题四:php 怎么获取验证码的值,接着怎么写 验证码一般都保存在session中,打印一下session的值,就能看到验证码对应的字段、值;
dump($_SESSION);

问题五:如何用html编写产生验证码 html是无法写出来的,需要一种动态脚本来写例如jsp、php、asp、aspx、c#都可以实现,不过服务器需要有解析脚本的功能才可以做动态站点,不知道你网站是用什么语言
麻烦采纳,谢谢!

问题六:验证码怎么写 先建立一个ValidateCodeaspx网页;然后在你的注册页面下面:输入这段代码 验证码: 这段代码是为了在注册页面显示四位数的 验证码!然后在验证码类中输入如下代码:using System; using SystemData; using SystemConfiguration; using System。

问题七:java 登录验证码代码怎么写 原理: 1随机生成4个数字 用到了Random类 2对这4个数字设置字体格式 用 setFont方法 3改变字体颜色用setColor 然后随机生成颜色 代码如下 package s1; import javaawtColor; import javaawtFont; import javaawtGraphics; import javaa

问题八:ios 登录界面注册和获取验证码怎么做 可以参考下面的例子:
##新建一个项目
现在xcode新建的项目都是自带故事板的, *** 作不是很方便,我们来把它改成说写代码
打开AppDelegateh文件,添加以下代码
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions { selfwindow=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; selfwindowrootViewController=[[ViewController alloc] init]; [selfwindow makeKeyAndVisible]; return YES; }
到此就完成了手写代码的第一步。
添加输入框和按钮
在ViewControllerh中添加以下代码
#import ViewControllerh
@interface ViewController ()
@property (nonatomic,strong) UITextField account;
@property (nonatomic,strong) UITextField password;
@property (nonatomic,strong) UIButton loginButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[selfview setBackgroundColor:[UIColor colorWithRed:51/2550 green:204/2550 blue:255/2550 alpha:1]];
_account=[[UITextField alloc] initWithFrame:CGRectMake(20, 200, selfviewframesizewidth-40, 50)];
_accountbackgroundColor=[UIColor whiteColor];
_accountplaceholder=[NSString stringWithFormat:@Email];
[selfview addSubview:_account];
_password=[[UITextField alloc] initWithFrame:CGRectMake(20, 260, selfviewframesizewidth-40, 50)];
_passwordbackgroundColor=[UIColor whiteColor];
_passwordplaceholder=[NSString stringWithFormat:@Password];
[selfview addSubview:_password];
_loginButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[_loginButton setFrame:CGRectMake>>

问题九:html获取验证码这个按钮的代码 直接插入一个input就行了,这个input没加什么样式,最多就是加了一个宽和高的定义吧。
刚试验了一下,宽和高都没加
问题十:网页中验证码代码怎么写啊 我举个的验证码产生的代码,你可以看看: 新建yanzhengma1aspxcs文件,写入一下代码: using System; using SystemCollections; using SystemConfiguration; using SystemData; using SystemLinq; using SystemWeb; using SystemWebSecurity; using SystemWebUI; using SystemWebUIHtmlControls; using SystemWebUIWebControls; using SystemWebUIWebControlsWebParts; using SystemXmlLinq; using SystemDrawing; public partial class yanzhengma : SystemWebUIPage { private SystemIOMemoryStream ms = newSystemIOMemoryStream(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { yanzhengmayzm = new yanzhengma(); Session[code1] = yzmCreateImage(5, ValidTypeNumeric); } } / / 验证码的类型 / public enum ValidType { / / 只有数字 / Numeric, / / 数字和英文字符 / NumericAndEnglishChar, / / 中文字符 / ChineseChar } / / 生成一个随机文字,保存在 Session[code1] / / 中字的个数 / 生成的文字 public string CreateImage(int count, ValidType type) { string ValidCode = GenCode(count,type); switch (type)>>

你用的是responseText肯下不行啊,你返回的是一个流。而不是一段文本,我觉得你不需要用ajax,你只要重新改变一下img对象的src属性就行了吧,还是指向这个servlet,相当于刷新一下这个。改变的src属性时,好像不刷新整个页面。

原理:

1生成一个随机字符串,

2将字符串放在Session中

3将字符串绘制在一个中

4,将用流的方式输出

代码:

/
  Project Name [JavaEE_Web]
  File Name      [CaptchaGeneratorServletjava]
  Creation Date  [2015-01-01]
  
  Copyright© geyyang@gmailcom All Rights Reserved
  
  Work hard, play harder, think big and keep fit
 /
package servletcases;
import javaawtColor;
import javaawtFont;
import javaawtGraphics2D;
import javaawtimageBufferedImage;
import javaioIOException;
import javautilRandom;
import javaximageioImageIO;
import javaxservletServletException;
import javaxservletServletOutputStream;
import javaxservletannotationWebServlet;
import javaxservlet><html>
<head>
<title>简单页面</title>
<script>
function yzm(){
var Num="";
for(var i=0;i<4;i++)
{
Num+=Mathfloor(Mathrandom()10);
}
documentgetElementById("yzphoto")value=Num;
documentgetElementById("yzm")value=Num;
}
function userLogin(){
var userName = documentgetElementById("userName")value;
var password = documentgetElementById("password")value;
var yztext = documentgetElementById("yztext")value;
var yzm = documentgetElementById("yzm")value;
if(userName != "jq"){
alert("用户名错误");
}else if(password != "123"){
alert("密码错误");
}else if(yztext != yzm){
alert("验证码错误");
}else{
alert("登陆成功");
}
locationreload();
}
</script>
</head>
<body onLoad="yzm()">
<div style="width:100%;text-align:center">
<h1>用户登录</h1>
<table>
<tr>
<td>用户名:</td>
<td><input id="userName" type="text" value=""/></td>
</tr>
<tr>
<td>密码:</td>
<td><input id="password" type="password" value=""/></td>
<tr>
<tr><td>
验证码:
</td>
<td><input id="yztext" type="text" value=""/><input style="width:50px;background-
color:red;color:blue" type="text" id="yzphoto" value=""/><input type="hidden" id="yzm"
value=""></td></tr>
<tr>
<td colspan="2" align="center"><input onclick="userLogin()" type="button" value="登陆"/></td>
</tr>
</table>
</div>
</body>
</html>

//验证码生成页面
<%@ page language="java" import="javautil" pageEncoding="GBK"%>
<%@ page import = " javaawt,javaawtimage,javaximageio " %>
<%@ page import = " javaioOutputStream " %>
<%!
Color getRandColor( int fc, int bc){
Random random = new Random();
if (fc > 255 ) fc = 255 ;
if (bc > 255 ) bc = 255 ;
int r = fc + randomnextInt(bc - fc);
int g = fc + randomnextInt(bc - fc);
int b = fc + randomnextInt(bc - fc);
return new Color(r,g,b);
}
%>
<%
try {
responsesetHeader( " Pragma " , " No-cache " );
responsesetHeader( " Cache-Control " , " no-cache " );
responsesetDateHeader( " Expires " , 0 );
int width = 60 , height = 20 ;
BufferedImage image = new BufferedImage(width, height, BufferedImageTYPE_INT_RGB);
OutputStream os = responsegetOutputStream();
Graphics g = imagegetGraphics();
Random random = new Random();
gsetColor(getRandColor( 200 , 250 ));
gfillRect( 0 , 0 , width, height);
gsetFont( new Font( " Times New Roman " ,FontPLAIN, 18 ));
gsetColor(getRandColor( 160 , 200 ));
for ( int i = 0 ;i < 155 ;i ++ )
{
int x = randomnextInt(width);
int y = randomnextInt(height);
int xl = randomnextInt( 12 );
int yl = randomnextInt( 12 );
gdrawLine(x,y,x + xl,y + yl);
}
String sRand = "" ;
for ( int i = 0 ;i < 4 ;i ++ ){
String rand = StringvalueOf(randomnextInt( 10 ));
sRand += rand;
gsetColor( new Color( 20 + randomnextInt( 110 ), 20 + randomnextInt( 110 ), 20 + randomnextInt( 110 )));
gdrawString(rand, 13 i + 6 , 16 );
}
sessionsetAttribute("vcode" ,sRand);
gdispose();
ImageIOwrite(image, "jpg" ,os);
osflush();
osclose();
os = null ;
responseflushBuffer();
outclear();
out = pageContextpushBody();
}
catch (IllegalStateException e)
{
Systemoutprintln(egetMessage());
eprintStackTrace();
} %>
//验证码使用页面
<%@ page language="java" import="javautil" pageEncoding="gbk"%>
<%
String path = requestgetContextPath();
String basePath = requestgetScheme()+"://"+requestgetServerName()+":"+requestgetServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 401 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'indexjsp' starting page</title>
<meta >(1)jsp代码:
<img id = "img_authcode" src="${ctx}/account/authcode" /><a href="javascript:;" onclick="javascript:documentgetElementById('img_authcode')setAttribute('src', '${ctx}/account/authcode' + Mathrandom())">换一换</a>
(2)java代码(该代码为我自己框架代码,跟servlet写法不一样的我都给你注释了):
public View authcode() throws IOException {
>这个我的想法是可以用js做。
不知道你的js水平如何,我先说下我的思路。
在js里先放一个计数器,用户每次登陆的时候发送一个ajax请求。如果成功则登陆,如果失败则计数器加一。
如果计算器大于你的登陆限制次数则,显示验证码。
至于如何显示验证码,我的想法是这样的。你先放一个display为none的div。里面放一张(就是验证码)。需要验证了就发送一个请求到后台获取一张验证码的,再把div的display设为block。
最后是验证码的验证,我觉得这个应该放在后台做,在一张可以看成是一个map的key,对应的验证码则是map的value。后台对应key的value检查用户输入的验证码对不对。不对则再刷新,页面报错。(这个用js控制)。
以上是我的思路,具体我也没有实现过。这个问题还蛮复杂的,你如果觉得我这套方案可行的话,可以继续追问我,我和你一起研究一下。

验证码的实现可以通过servlet的动态生成一张流,在jsp上指向servlet的地址就可以了!再把验证码的文字保存在session中!用户根据jsp页面输入的信息传入后台进行判断就可以了!具体代码网上很多!请多百度!


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13201173.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-06-19
下一篇 2023-06-19

发表评论

登录后才能评论

评论列表(0条)

保存