導航:首頁 > 編程語言 > java生成驗證碼jsp

java生成驗證碼jsp

發布時間:2021-02-27 03:22:58

java web 寫了個verificationCode.jsp驗證碼頁面,然後調用<img src="verificationCode.jsp"/>

我覺得還是路徑問題,你看看放入一個跟verificationCode.jsp路徑一樣的圖片進入能不能顯示出來

❷ java中 驗證碼代碼只能寫在Servlet和jsp中嗎

不是說只能放在servlet和jsp中,只能說是數據必須經過這2個地方。。。至於怎麼經過,怎麼調用,根據個人喜好和系統性能確定。

❸ 用java隨機生成四位驗證碼,只求編程代碼

不知道你問的是不是生成這種圖片驗證碼?
如果只要一個隨機四位數 那這行代碼就夠了(new Random().nextInt(9000) + 1000;),
如果是生成頁面圖片驗證碼就是下面的了:
//設定 響應模式
resp.setContentType("image/jpeg");

// 生成令牌環數據;
Integer token = new Random().nextInt(9000) + 1000;

// 保存令牌環數據到session中
req.getSession().setAttribute(IMAGE_TOKEN_NAME, token);

// 生成令牌環圖片
ServletOutputStream out = resp.getOutputStream();
BufferedImage img = new BufferedImage(60, 20,
BufferedImage.TYPE_INT_RGB);
Graphics g = img.getGraphics();
g.setColor(Color.YELLOW);
g.fillRect(0, 0, img.getWidth(), img.getHeight());
g.setColor(Color.BLUE);
g.setFont(new Font("", Font.BOLD, 18));
g.drawString(String.valueOf(token), 10, 16);
ImageIO.write(img, "jpg", out);
out.close();

❹ 在java頁面上,用jsp,怎樣寫一個驗證碼

//驗證碼生成頁面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import = " java.awt.*,java.awt.image.*,javax.imageio.* " %>
<%@ page import = " java.io.OutputStream " %>
<%!
Color getRandColor( int fc, int bc){
Random random = new Random();
if (fc > 255 ) fc = 255 ;
if (bc > 255 ) bc = 255 ;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r,g,b);
}
%>
<%
try {
response.setHeader( " Pragma " , " No-cache " );
response.setHeader( " Cache-Control " , " no-cache " );
response.setDateHeader( " Expires " , 0 );
int width = 60 , height = 20 ;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
OutputStream os = response.getOutputStream();
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor( 200 , 250 ));
g.fillRect( 0 , 0 , width, height);

g.setFont( new Font( " Times New Roman " ,Font.PLAIN, 18 ));
g.setColor(getRandColor( 160 , 200 ));
for ( int i = 0 ;i < 155 ;i ++ )
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt( 12 );
int yl = random.nextInt( 12 );
g.drawLine(x,y,x + xl,y + yl);
}
String sRand = "" ;
for ( int i = 0 ;i < 4 ;i ++ ){
String rand = String.valueOf(random.nextInt( 10 ));
sRand += rand;
g.setColor( new Color( 20 + random.nextInt( 110 ), 20 + random.nextInt( 110 ), 20 + random.nextInt( 110 )));
g.drawString(rand, 13 * i + 6 , 16 );
}
session.setAttribute("vcode" ,sRand);
g.dispose();

ImageIO.write(image, "jpg" ,os);
os.flush();
os.close();
os = null ;
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
catch (IllegalStateException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
} %>

//驗證碼使用頁面
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function refresh(){
co=document.getElementById("code");
co.src="vcode.jsp?vcode="+Math.random();
}
</script>
</head>

<body>
用戶名:<input type="text" name="name"><br/>
<img id="code" title="驗證碼" src="vcode.jsp"><a href="javascript:refresh();">換一張</a>
</body>
</html>

❺ 在我的java Web項目中為什麼我的jsp的驗證碼不能顯示啊其他項目可以顯示就是我的這一個項目不能顯示。

如果其他可以,這個不行,你可以試著重啟你的伺服器,清除瀏覽器緩存再打開試試..

❻ 在Javaweb中,我用一個jsp頁面生成一個驗證碼圖片並用session保存圖片上的數字,然後又

為什麼要放在session.太浪費資源。放在request裡面。每次請求的時候後台生成一個新的數字就request.setAttribult,頁面getAtrribult就可以了。你網路下用法就懂了

❼ java中如何在同一個jsp頁面中判斷圖片驗證碼與輸入的是否一致

這個問題很簡單的。我想你動態產生的驗證碼一定是一個單獨的頁面然後再把這個頁面導入到你的輸入信息的頁面的。你打開你的動態生成驗證碼的頁面。在裡面你一定可以找到一個session.setAttribute(""); 這個方法是把你驗證碼的值保存在session裡面。根據你的意思在用js彈出來驗證. 首先你在頁面中加一小腳本<% Stirng vcode= (String)session.getAttribute("驗證碼Key") %>然後在你的提交按鈕中加一個onClick事件... 請輸入驗證碼:<input type="text" id="txtvcode" name="txtvcode" /> <input type="button" name="text" id="text" value="提交" onClick="checkVcode('<%= vcode%>')" />這樣就可以把你動態生成的驗證碼值傳入到js的函數中去了。 <script> function checkVcode(vcode){ var txtvcode= document.getElementById("txtvcode").value; if(vcode==txtvcode){ alert("輸入驗證碼正確"); }else{ alert("輸入驗證碼錯誤"); } } </script>人在網吧。沒工具調試。我想這些代碼不會出問題的。

❽ J2EE中JSP頁面怎麼獲取JAVA類里生成的隨機驗證碼

直接 <img src="your image request url" >

❾ java驗證碼的問題。在驗證碼jsp中保存到session與響應到登陸頁面中的一致。但是登陸頁面中

看看是不是緩存的原因,你的獲取驗證碼url是否加了時間戳的標識。

閱讀全文

與java生成驗證碼jsp相關的資料

熱點內容
電腦如何替換文件內容 瀏覽:415
大數據沉澱 瀏覽:547
蘋果6怎麼找到運營商 瀏覽:747
iphone5連拍怎麼弄 瀏覽:323
上海樂客網路技術有限公司 瀏覽:439
計算機二級資料庫vfp 瀏覽:399
為什麼有護照大數據還要排查 瀏覽:241
為啥qq群文件下載不了 瀏覽:1
note3開機密碼設置 瀏覽:64
excel表文件怎麼按照日期排序 瀏覽:745
源網站招聘 瀏覽:729
java大數據技術有哪些 瀏覽:718
可信編程是什麼 瀏覽:824
大數據產生三個主要推手 瀏覽:385
js數字正則表達式 瀏覽:865
物流做數據的是什麼崗位 瀏覽:80
jsp傳到mysql亂碼 瀏覽:584
有什麼免費的鋼琴陪練app 瀏覽:720
品牌知名度的數據信息從哪裡找 瀏覽:206
網路技術簡介 瀏覽:96

友情鏈接