📄 index.jsp
字号:
<%@ page contentType="text/html; charset=GBK" language="java" pageEncoding="GBK"%>
<%@ page import="java.util.*"%>
<%
Random rand=new Random();
String[] sourcestr={"明","天","日","科","技","会","更","好","创","新"};
String str="";
String img="";
int intrand=0;
for(int i=0;i<4;i++){
intrand=Math.abs(rand.nextInt(10)); //生成一个10以内的随机数
str=str+sourcestr[intrand]; //获得随机字符串
img=img+"<img src='Images/checkcode/"+intrand+".gif' width='19' height='20'>"; //显示随面图片
}
session.setAttribute("checkcode",str); //将生成的随机字符串保存到Session中
%>
<script language="javascript">
function check(form){
if(form.manager.value==""){
alert("请输入用户名");form.manager.focus();return false;
}
if(form.PWD.value==""){
alert("请输入密码");form.PWD.focus();return false;
}
if(form.checkcode.value==""){
alert("请输入验证码");form.checkcode.focus();return false;
}
}
</script>
<html>
<head>
<title>随机显示图片</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="CSS/style.css" rel="stylesheet">
</head>
<body>
<table width="350" height="224" border="0" align="center" cellpadding="0" cellspacing="0" background="Images/login.jpg" class="tableBorder">
<tr>
<td height="84" align="center"> </td>
</tr>
<tr>
<td height="45" valign="top"><table width="62%" height="114" border="0" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="index_deal.jsp" onSubmit="return check(form1)">
<tr>
<td height="30" colspan="3" align="center"> 用户名:
<input name="manager" type="text" id="manager" size="20"></td>
</tr>
<tr>
<td height="27" colspan="3" align="center"> 密 码:
<input name="PWD" type="password" id="PWD" size="20"></td>
</tr>
<tr>
<td width="60%" height="27" align="right">验证码:
<input name="checkcode" type="text" id="checkcode" size="7"></td>
<td width="33%" align="left"> <%=img%></td>
<td width="7%" align="left"> </td>
</tr>
<tr>
<td colspan="3" align="center"><input name="Submit" type="submit" class="btn_grey" value="确认">
<input name="Submit2" type="reset" class="btn_grey" value="重置">
</td>
</tr>
</form>
</table></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -