张家力
欢迎使用张家力主页css
你好! 如果你想学习如何使用css编辑器, 可以仔细阅读这篇文章,了解一下css的基本语法知识。
css代码的灵活应用
代码详细
.box {
overflow: hidden;/* 超过box部分隐藏 */
width: 350px;
height: 250px;
background-color: rgb(0 0 0 / 10%);
box-shadow: 0 0 30px 15px rgb(0 0 0 / 15%);
border-radius: 10px;
display: flex;
margin: 10% auto;
}
.box:hover {
box-shadow: 0 0 30px 15px rgb(0 0 0 / 50%);
background-color: rgb(0 0 0 / 20%);
}
.acc {
width:150px;
outline: none;/* 鼠标点击输入是发生的变化 */
width: 80%;
border: none;
border-bottom: 1px solid darkviolet;
color: black;
background-color: rgba(0,0,0,0);
}
.submit {
width: 150px;
height: 2rem;
color: #f6f6f6;
background-image: linear-gradient(120deg, #e0c3fc 0%,#8ec5fc 100%);
border: none;
border-radius: 0.5rem;
}
a {
font-size: 15px;
margin-top: 3rem;
padding: 1rem 2rem;
color: #666;
}
a:hover {
color: rgb(144,129,241);
}
美化登录界面
我们可以用盒子(div)阔上我们的table和form来进行美化
.acc是美化输入框
.box美化主页面
a是忘记密码和注册账号的美化
设计主题参考
<body onload="robtRand()">
<%
session.setAttribute("username", null);
session.setAttribute("usertype", null);
%><!--重制session-->
<div class="box">
<form action="loginDo.jsp" method="post">
<table align="center" style="text-align:center;">
<tr>
<td colspan="3"><h1 align="center">Login</h1></td>
</tr>
<tr>
<td>账号:</td>
<td><input class="acc" name="userName"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" class="acc" name="password" id="password">
<input type="hidden" class="acc" name="hidden" id="hidden">
</td>
</tr>
<tr>
<td>验证码</td>
<td><input class="acc" name="userKey"></td>
<td> <span id="passKey" onclick="robtRand()"></span>
<!-- <img src="yzm.jsp" alt="验证码"
style="width: 110px; height: 22px; position:absolute;top:154px;"
οnclick="this.src='yzm.jsp? rand='+Math.random()" />如果使用这种类型验证码必须从外部进来 -->
</td>
</tr>
<tr>
<td colspan="3">
<input type="submit" class="submit" value="登录" onclick="md5()">
</td>
</tr>
<tr>
<td align="left">
<a href="rige.jsp">注册账号</a>
</td>
<td align="right" colspan="2">
<a href="indexf.jsp">忘记密码</a>
</td>
</tr>
</table>
</form>
</div>
</body>
ysm.jsp外部验证码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.io.IOException,
java.awt.*,java.awt.image.BufferedImage,
java.util.*,javax.imageio.ImageIO"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>new jsp</title>
</head>
<body>
<%
String code = "";
for (int i = 0; i < 4; i++) {
int num = (int) (Math.random() * 10);
code += num;
}
session.setAttribute("key", code);
// 设置验证码字体的大小
int fontSize = 18;
// 设置验证码图片的大小
int width = (4 + 1) * fontSize, height = 2 * fontSize;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
// 设置验证码图片背景颜色为白色
graphics.setColor(Color.white);
graphics.fillRect(0, 0, width, height);
// 绘制边框
graphics.setColor(Color.gray);
graphics.drawRect(0, 0, width - 1, height - 1);
// 绘制干扰线
graphics.setColor(Color.gray);
for (int i = 0; i < 5; i++) {
int x1 = (int) (Math.random() * width);
int y1 = (int) (Math.random() * height);
int x2 = (int) (Math.random() * width);
int y2 = (int) (Math.random() * height);
graphics.drawLine(x1, y1, x2, y2);
}
// 绘制验证码
graphics.setColor(Color.blue);
Font font = new Font("Times New Roman", Font.PLAIN, fontSize);
graphics.setFont(font);
for (int i = 0; i < 4; i++) {
int x = i * fontSize + (int) (Math.random() * 5);
int y = fontSize + (int) (Math.random() * 5);
graphics.drawString(code.substring(i, i + 1), x, y);
}
// 将验证码图片输出到页面
response.setContentType("image/jpeg");
ImageIO.write(image, "jpeg", response.getOutputStream());
%>
</body>
</html>
生成验证码
用前端java生成随机数当做验证码,然后使用cook可用于传输到后端进行处理
<script src="js/md5.js"></script> <!--onclick="md5()" -->
<script type="text/javascript">
function robtRand(){//随机数生成
var x = Math.round(Math.random()*9000+1000);
document.getElementById("passKey").innerHTML=x;
document.cookie = "robotKey=" + x;
}
function md5() //密码加密
{
//alert(hex_md5(document.getElementById("password").value));
document.getElementById("hidden").value=hex_md5(document.getElementById("password").value);
}
</script>
md5.js
/*
* A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
* Digest Algorithm, as defined in RFC 1321.
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
/*
* Configurable variables. You may need to tweak these to be compatible with
* the server-side, but the defaults work in most cases.
*/
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
/*
* These are the functions you'll usually want to call
* They take string arguments and return either hex or base-64 encoded strings
*/
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
/*
* Perform a simple self-test to see if the VM is working
*/
function md5_vm_test()
{
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}
/*
* Calculate the MD5 of an array of little-endian words, and a bit length
*/
function core_md5(x, len)
{
/* append padding */
x[len >> 5] |= 0x80 << ((len) % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
for(var i = 0; i < x.length; i += 16)
{
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
}
return Array(a, b, c, d);
}
/*
* These functions implement the four basic operations the algorithm uses.
*/
function md5_cmn(q, a, b, x, s, t)
{
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}
/*
* Calculate the HMAC-MD5, of a key and some data
*/
function core_hmac_md5(key, data)
{
var bkey = str2binl(key);
if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
var ipad = Array(16), opad = Array(16);
for(var i = 0; i < 16; i++)
{
ipad[i] = bkey[i] ^ 0x36363636;
opad[i] = bkey[i] ^ 0x5C5C5C5C;
}
var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
return core_md5(opad.concat(hash), 512 + 128);
}
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safe_add(x, y)
{
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
/*
* Bitwise rotate a 32-bit number to the left.
*/
function bit_rol(num, cnt)
{
return (num << cnt) | (num >>> (32 - cnt));
}
/*
* Convert a string to an array of little-endian words
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
*/
function str2binl(str)
{
var bin = Array();
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz)
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
return bin;
}
/*
* Convert an array of little-endian words to a string
*/
function binl2str(bin)
{
var str = "";
var mask = (1 << chrsz) - 1;
for(var i = 0; i < bin.length * 32; i += chrsz)
str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
return str;
}
/*
* Convert an array of little-endian words to a hex string.
*/
function binl2hex(binarray)
{
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for(var i = 0; i < binarray.length * 4; i++)
{
str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
}
return str;
}
/*
* Convert an array of little-endian words to a base-64 string
*/
function binl2b64(binarray)
{
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var str = "";
for(var i = 0; i < binarray.length * 4; i += 3)
{
var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)
| (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
| ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
for(var j = 0; j < 4; j++)
{
if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
}
}
return str;
}
读取信息表格菜单美化
/* 表格整体样式 */
input {
width:150px;
border:none;
}
table{
margin: 0 0 0 0 ;
border-collapse:collapse; /* 合并为单一的边框线 */}
table td,th{
padding:5px;
border:1px solid black;/* 设置td样式 */
}
a{ color:black; text-decoration:none;padding:1px 4px;" }
ps例子:
adm.jsp
<body>
<%
Object type = session.getAttribute("usertype");
if(type==null){
response.setHeader("refresh","0;url=index.jsp");
}
Object page1 = session.getAttribute("page1");
Object page2 = session.getAttribute("page2");
if(type.equals("管理员")){
%>
<h1 align="center">账号表</h1>
<form action="changeM.jsp">
<div align="center">
<table style="text-align:center" >
<tr>
<td>序号</td>
<td>账号名</td>
<td>邮箱</td>
<td>类型</td>
</tr>
<%
operation op = new operation();
String sql = "select * from person limit "+page1+","+((Integer)page1+5)+"";
ResultSet rs = op.getSQL(sql);
while(rs.next()){//具体情况具体考虑
//id为机器生成无法更改
String id = rs.getString("id");
out.print("<tr><td>"+id+"</td>");
out.print("<td>"+rs.getString("user")+"</td>");
out.print("<td><input name='y"+id+"' value='"+rs.getString("邮箱")+"'></td>");
out.print("<td><input name='t"+id+"' value='"+rs.getString("type")+"'></td></tr>");
}
%>
<tr>
<td colspan="4" align="center">
<a href="admtop.jsp"><button type="button">上一页</button></a>
<a href="admNext.jsp"><button type="button">下一页</button></a>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: left;border-right:0">
<input type="submit" value="保存" style="width:40px">
</input></td>
<td colspan="2" style="text-align: right;border-left:0">
<a href="rige.jsp" style="background-color:buttonface;width:40px">增加</a>
</td>
</tr>
</table>
</div>
</form>
<%}
%>
<h1 align="center">购物表</h1>
<form action="changeDw.jsp">
<div align="center">
<table border="1" align="center" style="text-align:center" >
<tr>
<td>用户名</td>
<td>车辆类型</td>
<td>销售情况</td>
<td>售后情况</td>
<td>接待销售</td>
</tr>
<%
operation op = new operation();
String sql = "select * from user_info limit "+page2+","+((Integer)page2+5)+"";
int i = (Integer)page2;
ResultSet rs = op.getSQL(sql);
while(rs.next()){//具体情况具体考虑
out.print("<tr><td>"+rs.getString("用户名")+"</td>");
out.print("<td>"+rs.getString("车辆类型")+"</td>");
out.print("<td><input name='x"+i+"' value='"+rs.getString("销售情况")+"'></td>");
out.print("<td><input name='s"+i+"' value='"+rs.getString("售后情况")+"'></td>");
out.print("<td><input name='j"+i+"' value='"+rs.getString("接待销售")+"'></td></tr>");
i++;
}
%>
<tr>
<td colspan="5" align="center">
<a href="gtop.jsp"><button type="button">上一页</button></a>
<a href="gNext.jsp"><button type="button">下一页</button></a>
</td>
</tr>
</table>
</div>
<h4 align="center"><input type="submit" value="更改"></h4>
</form>
<h5 align="center"><a href="index.jsp">返回登录页面</a></h5>
</body>
如果这里又提交保存的话建议
<%//changeM.jsp
operation op = new operation();
Object page1 = session.getAttribute("page1");//第一个表
String sql = "select * from person limit "+page1+","+((Integer)page1+5)+"";
ResultSet rs = op.getSQL(sql);
while(rs.next()){
String id = rs.getString("id");
String yid = request.getParameter("y"+id);
String tid = request.getParameter("t"+id);
String upsql = "update person set 邮箱='"
+yid+"',type='"+tid+"' where id="+id+";";
op.setSQL(upsql);
}
response.setHeader("refresh", "0;url=adm.jsp");
%>
<%//changeDw.jsp
operation op = new operation();
Object page2 = session.getAttribute("page2");//第二个表
int i = (Integer)page2;
String sql = "select * from user_info limit "+page2+","+((Integer)page2+5)+"";
ResultSet rs = op.getSQL(sql);
while(rs.next()){
String u = rs.getString("用户名");//下标情况定位
String l = rs.getString("车辆类型");//具体情况具体考虑
String x = request.getParameter("x"+i);//获取页面需要更改的信息
String s = request.getParameter("s"+i);
String j = request.getParameter("j"+i);
sql = "update user_info set 销售情况='"
+x+"',售后情况='"+s+"',接待销售='"+j+"' where 用户名='"
+u+"' and 车辆类型='"+l+"';";
out.print(sql+"<br>");
op.setSQL(sql);
i++;
}
response.setHeader("refresh", "0;url=adm.jsp");
%>