【网页特效代码-页面特效】模拟静态网页分页的特效代码
frontpage特效代码-s利用这些代码可生成你想要的动画

位置: <body>与</body>之间插入代码一、在网页源代码中加入下面的代码,则该窗口将在20秒钟之后自动关闭!这与跳出式小窗口配合使用是再好不过啦!代码中“i=20”表示关闭的延迟时间为20秒,可任意修改。
<script language="javascript"><!--function clock(){i=i-1document.title="本窗口将在"+i+"秒后自动关闭!";if(i>0)setTimeout("clock();",1000);else self.close();}var i=20clock();//--></script>二、让文字跟心脏一样跳动,扑咚、扑咚……<style><!--#glowtext{filter:glow(color=ff0000,strength=2);width:100%;}--></style><script language="JavaScript1.2">function glowit(which){if (document.all.glowtext[which].filters[0].strength==2) document.all.glowtext[which].filters[0].strength=1elsedocument.all.glowtext[which].filters[0].strength=2}function glowit2(which){if (document.all.glowtext.filters[0].strength==2) document.all.glowtext.filters[0].strength=1elsedocument.all.glowtext.filters[0].strength=2}function startglowing(){if (document.all.glowtext&&glowtext.length){for (i=0;i<glowtext.length;i++)eval('setInterval("glowit('+i+')",150)')}else if (glowtext)setInterval("glowit2(0)",150)}if (document.all)window.onload=startglowing</script><span id="glowtext"><font color="F5D20A" " face="宋体" size="2">你的心是不是跟这一样跳?</font></span>三、跟随鼠标的漂亮星星<SCRIPT language=JavaScript><!--if (document.all){//To add more stars simply add more colours in below array!!colours=new Array('ff0000','00ff00','3366ff','ff00ff','ffa500','ff ffff','fff000')//Alter nothing below!!amount=colours.length;YgetDelay=0,XgetDelay=0,Ydelay=0,Xdelay=0,step=0.2,currStep=0,my=0, mx=0;document.write('<div id="ie" style="position:absolute;top:0;left:0; "><div style="position:relative">');for (i=0; i < amount; i++)document.write('<div id="iestars" style="position:absolute;top:0px; left:0px;height:50px;width:50px;font-family:Courier New;font-size:5px; color:'+colours[i]+';padding-top:20px;text-align:center">.</div>');document.write('</div></div>');ini=1;gstep=1;function iMouse(){my=event.y;mx=event.x;}document.onmousemove=iMousefunction dim(){ini-=gstep;dt=setTimeout('dim()',10);if (ini < 2){clearTimeout(dt);glow();}}function glow(){ini+=gstep;gt=setTimeout('glow()',10);if (ini > 14){clearTimeout(gt);dim();}}function stars(){ie.style.top=document.body.scrollTop; for (i=0; i < amount; i++){var layer=iestars[i].style;layer.filter='glow(color='+colours[i]+', strength='+ini+')';layer.top= Ydelay+100*Math.sin((5*Math.sin((currStep-15.99)/10))+ i*70)*Math.sin((currStep)/10)*Math.cos((currStep+i*25)/10);layer.left=Xdelay+180*Math.cos((5*Math.sin((currStep-15.99)/10))+ i*70)*Math.sin((currStep)/10)*Math.cos((currStep+i*25)/10);}currStep+=step;}function delay(){Ydelay = YgetDelay+=(my-YgetDelay)*1/20;Xdelay = XgetDelay+=(mx-XgetDelay)*1/20;stars();setTimeout('delay()',10);}delay();glow();}//--></SCRIPT>四、让屏幕抖动一阵<input onclick="www_helpor_net(2)" type="button" value="地震啦!!!"><script language="JavaScript"><!--function surfto(form) {var myindex=form.select1.selectedIndexif (form.select1.options[myindex].value != null) {parent.main.location.href=form.select1.options[myindex].value; }}// --></script><script language="JavaScript1.2"><!--function www_helpor_net(n) {if (window.top.moveBy) {for (i = 10; i > 0; i--) {for (j = n; j > 0; j--) {window.top.moveBy(0,i);window.top.moveBy(i,0);window.top.moveBy(0,-i);window.top.moveBy(-i,0);}}}alert(" 没吓坏吧!!! ");}// --></script>五、特殊效果的按钮<style type="text/css"><!--.over {color:yellow; background: navy}.down {color:yellow; background: navy; font-style: italic}--></style><inputtype="Button" value="按钮也疯狂" name="Button"onMouseOver="this.className='over';"onMouseOut="this.className='';this.value='按钮也疯狂'"onMouseDown="this.className='down';"onMouseUp="this.className='over';"onClick="this.value='我真的好喜欢你!'">六、文本自动向上循环滚动,鼠标放到上面还会暂时停下来。
【IT专家】网页特效集锦

网页特效集锦2008/02/11 0 典型特效1、收藏本站说明:点击即可把你的网站添加到浏览器的收藏菜单下代码:span ‘ycrc’,’盐城人才网’)title= 收藏盐城人才网收藏本站/span 2、设为首页说明:点击即可把你的网站设置为浏览器的起始页代码:span quot;varstrHref=window.location.href;this.style.behavior=‘url(#default#homepage)’;this.setHome Page(‘ycrc’);>3、去掉超链接的下划线说明:有时候看着那超链接的下划线挺讨厌的,把下面这段代码放到网页源代码head 与/head 之间,下划线就无影无踪啦!注意,网页的body 标签里不能再有link 之类的属性,否则本效果会失效!代码:style TYPE= text/css !--A:link{text-decoration:none}A:visited{text- decoration:none}A:hover {color: #ff00ff;text-decoration:underline}-- /style 4、自动刷新网页说明:在HTML 的与之间加入下面这段代码,则在5 分钟之后正在浏览的页面将会自动变为target.html 这一页。
代码中300 为刷新的延迟时间,以秒为单位。
targer.html 为你想转向的目标页,若为本页则为自动刷新本页。
代码:meta http- equiv= refresh content= 300; url=target.html 5、刷新本页说明:点击即可刷新本页。
代码: a href= javascript:location.reload() target= _self 刷新/a 6、返回到上一页说明:点击即可返回到上一页面。
代码: a href= javascript:history.back(-1) 返回上一页/a 7、跳出小窗口说明:在打开有下面这段代码的页面时将会跳出一个468x60 大小的小窗口。
HTML特效代码全套汇编(完整编辑全收录)

1) 贴图:<img src="图片地址">2)加入连接:<a href="所要连接的相关地址">写上你想写的字</a>3)在新窗口打开连接:<a href="相关地址" target="_blank">写上要写的字</a>消除连接的下划线在新窗口打开连接:<a href="相关地址" style="text-decoration:none"target="_blank">写上你想写的字</a>4)移动字体(走马灯):<marquee>写上你想写的字</marquee>5)字体加粗:<b>写上你想写的字</b>6)字体斜体:<i>写上你想写的字</i>7)字体下划线: <u>写上你想写的字</u>8)字体删除线: <s>写上你想写的字</s>9)字体加大: <big>写上你想写的字</big>10)字体控制大小:<h1>写上你想写的字</h1> (其中字体大小可从h1-h5,h1最大,h5最小)11)更改字体颜色:<font color="#value">写上你想写的字</font>(其中value值在000000与ffffff(16位进制)之间12)消除连接的下划线:<a href="相关地址" style="text-decoration:none">写上你想写的字</a>13)贴音乐:<embed src=音乐地址width=300 height=45 type=audio/mpeg autostart="false">14)贴flash: <embed src="flash地址" width="宽度" height="高度">15)贴影视文件:<img dynsrc="文件地址" width="宽度" height="高度" start=mouseover>16)换行:<br>17)段落:<p>段落</p>18)原始文字样式:<pre>正文</pre>19)换帖子背景:<body background="背景图片地址">20)固定帖子背景不随滚动条滚动:<body background="背景图片地址" bodybgproperties=fixed>21)定制帖子背景颜色:<body bgcolor="#value">(value值见10)22)帖子背景音乐:<bgsound="背景音乐地址" loop=infinite>23)贴网页:<iframe src="相关地址" width="宽度" height="高度"></iframe>HTML特效代码1。
html特效代码大全精美

html特效代码大全精美 html特效代码大全精通HTML特效代码1。
忽视右键或2。
加入背景音乐IE:NS:*.mid你的背景音乐的midi格式文件3。
简单的window.open方法onclick="javascript :window.open(文件路径/文件名,newwindow, toolbar=no,scrollbars=yes,resizable=no,top=0,left=0,width=400,height=300);">文字或图片参数解释:js脚本结束4。
简单的页面加密5。
拉动页面时背景图不动6。
让浏览器在保存页面时保存失败标内加入如:9。
网页自动关闭这个窗口会在10秒过后自动关闭,而且不会出现提示.10。
网页自动刷新在head部记入其中20为20秒后自动刷新,你可以更改为任意值。
11。
网页自动转页#前面#后面 height=100% width=100%>13。
返回上一页『返回上一页』14。
关闭窗口『关闭窗口』15。
关于iframe的透明背景16. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键no 可用于Table17. 取消选取、防止复制18.onpaste="return false" 不准粘贴19.oncopy="return false;" oncut="return false;" 防止复制20. IE地址栏前换成自己的图标21. 可以在收藏夹中显示出你的图标22. 关闭输入法23. 永远都会带着框架24. 防止被人frame25. 网页将不能被另存为27.删除时确认删除28.屏蔽功能键Shift,Alt,Ctrl29. 网页不会被缓存或者或31.不要滚动条?让竖条没有:让横条没有:两个都去掉?更简单了32.怎样去掉图片链接点击后,图片周围的虚线?33.电子邮件处理提交表单34.在打开的子窗口刷新父窗口的代码里如何写?window.opener.location.reload()35.如何设定打开页面的大小打开页面的位置36.在页面中如何加入不是满铺的背景图片,拉动页面时背景图不动37. 检查一段字符串是否全由数字组成38. 获得一个窗口的大小document.body.clientWidth; document.body.clientHeight 39. 怎么判断是否是字符if (/[^/x00-/xff]/g.test(s)) alert("含有汉字");else alert("全是字符");40.TEXTAREA自适应文字行数的多少Barcode区域中:")for(var i=1;idocument.write("")document.write("200){document.forms[0]["txt"+b].value="链接超时"}else{document.forms[0]["txt"+b].value="时间"+tim/10+"秒"} b++ } function run(){for(var i=1;i")}run()46. 各种样式的光标auto :标准光标default :标准箭头hand :手形光标wait :等待光标text :I形光标vertical-text :水平I形光标no-drop :不可拖动光标not-allowed :无效光标help :?帮助光标all-scroll :三角方向标move :移动标crosshair :十字标e-resizen-resizenw-resizew-resizes-resizese-resizesw-resize47、禁止鼠标右键,把Demo的图片全都设为表格的背景,表格的大小与图片的大小一样。
JS代码实现table数据分页效果

JS代码实现table数据分页效果第⼀个:实现的很常见很简单的显⽰页数翻页 效果图:•这是HTML代码,很简单滴(我好像看到了被嫌弃的⼩眼神)<!DOCTYPE html><html><head lang="en"><meta charset="UTF-"><script src="js/jquery-...js"></script><script src="js/demo.js"></script><link rel="stylesheet" href="js/demo.css"/><title></title></head><body><table width="" border=""><thead><tr><th>姓名</th><th>性别</th><th>编号</th><th>年龄</th></tr></thead><tbody><tr><td>张三</td><td>男</td><td></td><td></td></tr><tr><td>tom</td><td>男</td><td></td><td></td></tr><tr><td>李四</td><td>男</td><td></td><td></td></tr><tr><td>⼆蛋</td><td>男</td><td></td><td></td></tr><tr><td>⼆丫</td><td>⼥</td><td></td><td></td></tr></tbody></table></body></html>•下⾯就是JS代码了$(function(){var $table=$('table');//获取表格对象var currentPage=;//设置当前页默认值为var pageSize=;//设置每⼀页要显⽰的数⽬$table.bind('paging', function () {$table.find('tbody tr').hide().slice(currentPage*pageSize,(currentPage+)*pageSize).show();//先将tbody中所有的⾏隐藏,再通过slice结合当前页数和页⾯显⽰的数⽬展现数据});var sumRows=$table.find('tbody tr').length;//获取数据总⾏数var sumPages=Math.ceil(sumRows/pageSize);//得到总页数var $pager=$('<div class="page"></div>');for(var pageIndex=;pageIndex<sumPages;pageIndex++){$('<a href="#"><span>'+(pageIndex+)+'</span></a>').bind("click",{"newPage":pageIndex},function(event){ currentPage=event.data["newPage"];$table.trigger("paging");//为每⼀个要显⽰的页数上添加触发分页函数}).appendTo($pager);$pager.append(" ");}$pager.insertAfter($table);$table.trigger("paging");});第⼆个:实现前进页和后退页 效果图:•这是全部代码,⽤得原⽣JS,依然还是很简单滴(好像对原⽣js有种莫名的喜爱,有⽊有)<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-" /><title>table分页</title></head><body><style type="text/css">.tablebox{border:solid px #ddd;}.tablebox td{text-align:center;border:solid px #ddd;padding:px;}</style><div style="width:px;margin: auto;"><table class="tablebox" width="" border="" cellpadding="" cellspacing=""><tbody id="table"><tr><td></td><td> </td><td> </td><td> </td><td> </td></tr><tr><td></td><td> </td><td> </td><td> </td><td> </td></tr><tr><td></td><td> </td><td> </td><td> </td><td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td> </tr><tr><td></td><td> </td> <td> </td> <td> </td> <td> </td><td> </td><td> </td><td> </td><td> </td></tr></tbody></table><div style="height:px;margin:px ;"><span id="spanFirst">第⼀页</span><span id="spanPre">上⼀页</span><span id="spanNext">下⼀页</span><span id="spanLast">最后⼀页</span>第<span id="spanPageNum"></span>页/共<span id="spanTotalPage"></span>页</div></div><script type="text/javascript">var theTable = document.getElementById("table");var totalPage = document.getElementById("spanTotalPage"); var pageNum = document.getElementById("spanPageNum"); var spanPre = document.getElementById("spanPre");var spanNext = document.getElementById("spanNext");var spanFirst = document.getElementById("spanFirst");var spanLast = document.getElementById("spanLast");var numberRowsInTable = theTable.rows.length;var pageSize = ;var page = ;//下⼀页function next() {hideTable();currentRow = pageSize * page;maxRow = currentRow + pageSize;if ( maxRow > numberRowsInTable )maxRow = numberRowsInTable;for ( var i = currentRow; i< maxRow; i++ ) {theTable.rows[i].style.display = '';}page++;if ( maxRow == numberRowsInTable ){nextText();lastText();}showPage();preLink();firstLink();}//上⼀页function pre() {hideTable();page--;currentRow = pageSize * page;maxRow = currentRow - pageSize;if ( currentRow > numberRowsInTable )currentRow = numberRowsInTable;for ( var i = maxRow; i< currentRow; i++ ) {theTable.rows[i].style.display = '';}if ( maxRow == ) {preText();firstText();}showPage();nextLink();lastLink();}//第⼀页function first() {hideTable();page = ;for ( var i = ; i<pageSize; i++ ) {theTable.rows[i].style.display = '';}showPage();preText();}//最后⼀页function last() {hideTable();page = pageCount();currentRow = pageSize * (page - );for ( var i = currentRow; i<numberRowsInTable; i++ ) {theTable.rows[i].style.display = '';}showPage();preLink();nextText();firstLink();}function hideTable() {for ( var i = ; i<numberRowsInTable; i++ ) {theTable.rows[i].style.display = 'none';}}function showPage() {pageNum.innerHTML = page;}//总共页数function pageCount() {var count = ;if ( numberRowsInTable%pageSize != ) count = ;return parseInt(numberRowsInTable/pageSize) + count;}//显⽰链接function preLink() { spanPre.innerHTML = "<a href='javascript:pre();'>上⼀页</a>"; }function preText() { spanPre.innerHTML = "上⼀页"; }function nextLink() { spanNext.innerHTML = "<a href='javascript:next();'>下⼀页</a>"; }function nextText() { spanNext.innerHTML = "下⼀页"; }function firstLink() { spanFirst.innerHTML = "<a href='javascript:first();'>第⼀页</a>"; }function firstText() { spanFirst.innerHTML = "第⼀页"; }function lastLink() { spanLast.innerHTML = "<a href='javascript:last();'>最后⼀页</a>"; }function lastText() { spanLast.innerHTML = "最后⼀页"; }//隐藏表格function hide() {for ( var i = pageSize; i<numberRowsInTable; i++ ) {theTable.rows[i].style.display = 'none';}totalPage.innerHTML = pageCount();pageNum.innerHTML = '';nextLink();lastLink();}hide();</script></body></html>以上内容是⼩编给⼤家介绍的JS代码实现table数据分页效果,希望对⼤家有所帮助,如果⼤家还有任何问题欢迎给我留⾔,⼩编会及时回复⼤家的,在此也⾮常感谢⼤家对⽹站的⽀持!。
伪静态规则代码

伪静态规则代码一、什么是伪静态规则代码在网站开发中,伪静态是指通过对URL进行重写,使其看起来像是静态页面的一种技术。
伪静态规则代码是指用来实现伪静态的一段代码或配置。
传统动态网页的URL通常包含参数,例如:。
而使用伪静态后,URL会变得更加友好和美观,例如:。
通过使用伪静态规则代码,可以提升网站的用户体验和搜索引擎优化效果。
二、为什么使用伪静态规则代码1. 改善用户体验动态网址通常包含大量参数和特殊字符,不易记忆和分享。
而采用伪静态后,URL会变得简洁、有意义且易于理解。
这有助于提高用户对网站内容的识别度和理解度。
2. 提升搜索引擎优化效果搜索引擎更喜欢处理静态页面而非动态页面。
通过使用伪静态规则代码,可以将动态生成的页面转换为看起来像是静态页面的形式呈现给搜索引擎爬虫。
这有助于提高网站在搜索引擎结果页面中的排名。
3. 方便URL的管理和维护动态网址通常包含大量参数,不方便管理和维护。
而使用伪静态后,URL会变得简洁明了,易于管理和维护。
三、如何编写伪静态规则代码1. 选择合适的伪静态规则代码方式在编写伪静态规则代码之前,需要先选择合适的方式来实现伪静态。
常见的方式包括:•Apache服务器下使用.htaccess文件•Nginx服务器下使用rewrite模块•IIS服务器下使用URL Rewrite模块根据所使用的服务器类型和具体需求,选择相应的方式进行配置。
2. 编写伪静态规则代码示例(以Apache服务器为例)a. 创建.htaccess文件首先,在网站根目录下创建一个名为.htaccess的文件。
b. 启用.htaccess确保Apache服务器已开启.htaccess功能。
在主配置文件或虚拟主机配置中添加以下内容:<Directory "/path/to/your/website">AllowOverride All</Directory>c. 编写伪静态规则代码在.htaccess文件中添加以下示例代码:RewriteEngine OnRewriteBase /# 将 /article.php?id=1 重写为 /article/1.htmlRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^article/([0-9]+)\.html$ article.php?id=$1 [L]在上述示例代码中,RewriteEngine On表示启用URL重写功能,RewriteBase /表示基础重写路径。
静态网页代码集

Html语言2.1头部标记:<head></head> <!—描述web页面相关的各种信息-->1.<title></title><!—标题栏标记-->2.<meta><!—描述页面信息--><meta name=”description” contect=”阿里巴巴是(b2b)”/> description是web界面的简要说明<meta name=”Generator” contect=”Microsoft FrontPage 4.0”> Generator指定web界面的生成工具<meta name=”Author” contect=”Nadia”> Author制定web界面的作者姓名<meta name=”Robots” contect=”all|none|index|noindex|follow|nofollow”>3. 1.换行<br>;2.原样显示标记<pre></pre>3.缩排标记<blockquote></blockquote>4.水平线<hr> 属性去3D阴影noshade5.<body backgroud=”bg.jpg”>4.有序列表:<ol type=”1” state=”1”> 样式A I i a<li>…</li><li>…</li></ol>5.无序列表:<ul><li type=”Disc”></li></ul>实心圆圈Disc 空心圆圈Circle 小方块Sqiare6.超链接:锚点链接<a href=”#1”>点击跳转到链接</a><a name=”1”>链接的目标</a>超链接<a href=”” titile=”链接百度网” target=”_blank”>百度</a><a href=”work.html” titile=”链接内部” >内部链接显示在本页</a>外部E-mail链接:<a href=”mailto:334860757@?cc=1525528088@&Subject=网页开发&Body=超链接的使用方法”>向334860757发送邮件</a>7.图片<img src=”bg.jpg” align=”top” width=”100” height=”66”>8.div中添加网页<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>无标题文档</title></head><body><div align="center"><div style="width:800px; height:400px;"><div style="width:80px; height:400px;float:left;"><a href="" target="s">链接一</a><br /><a href="" target="s">链接二</a><br /><a href="" target="s">链接三</a></div><div style="width:720px; height:400px; float:left;"><iframe name="s" id="s" width="720" height="400" frameborder="0"></iframe></div></div></div></body></html>9.控件的代码:滚动字幕<marquee scrollamount=3 FONT style="COLOR=FF0000; FILTER: shadow(color=FFFF33 ); FONT-FAMILY: 隶书; FONT-SIZE: 25pt; WIDTH: 100%"></marquee>音频视频<embed src=”1.avi” loop=”false”></embed>10.样式表内部样式:<font style=”font-family:”楷体”;font-weight:bold;”>嵌入样式:<head><style type=”test.css”></style></head>外部样式:<link href=”样式地址” rel=”stylesheet” type=”text.css”>输入样式表:<style>@import url(http://......)</style>11.鼠标光标属性:<span style=”cursor=move”></span>12.滤镜属性:Filter:alpha(opacity=opcity,…..)Alpha不透明度Blur 图片模糊Chroma 对象指定颜色透明色dropShadow 对象产生投影效果FlipH水平翻转FlipV垂直Glow边缘发光Gray变灰度图Invert可视化属性全部翻转Mask覆盖膜Shadow投影Wave垂直波浪打乱Xray X光照效果13.背景音乐:<bgsound src=e:\mp3\歌曲1\死了都要爱.mp3>。
JavaWeb简单的分页显示实例代码

JavaWeb简单的分页显⽰实例代码本⽂通过两个⽅法:(1)计算总的页数。
(2)查询指定页数据,实现简单的分页效果。
思路:⾸先得在 DAO 对象中提供分页查询的⽅法,在控制层调⽤该⽅法查到指定页的数据,在表⽰层通过 EL 表达式和JSTL 将该页数据显⽰出来。
先给⼤家展⽰下效果图:题外话:该分页显⽰是⽤ “表⽰层-控制层-DAO层-数据库”的设计思想实现的,有什么需要改进的地⽅⼤家提出来,共同学习进步。
废话不多说了,开始进⼊主题,详细步骤如下所⽰:1.DAO层-数据库JDBCUtils 类⽤于打开和关闭数据库,核⼼代码如下:import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;public class JDBCUtils {private Connection conn=null;private PreparedStatement pstmt=null;/*** connect 连接数据库* @return*/public Connection connect(){String user="root";String password="1234";String driverClass = "com.mysql.jdbc.Driver";String jdbcUrl = "jdbc:mysql://localhost:3306/book";try {Class.forName(driverClass);conn = DriverManager.getConnection(jdbcUrl, user, password);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return conn;}/*** close 关闭数据库* @param conn* @param pstmt* @param resu*/public void close(Connection conn,PreparedStatement pstmt,ResultSet result){if(conn != null){try {conn.close();} catch (SQLException e) {// TODO Auto-generated catch block}}if(pstmt != null){try {pstmt.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}if(result != null){try {result.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}UserDao 类中的⽅法 getPage() 和⽅法 listUser() 分别⽤来计算总页数和查询指定页的数据,核⼼代码如下:import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import com.db.JDBCUtils;public class UserDao {/*** 计算总的页数* @return*/public int getPage(){int recordCount=0,t1=0,t2=0;PreparedStatement pstmt=null;ResultSet result=null;JDBCUtils jdbc=new JDBCUtils();Connection conn=jdbc.connect();String sql="select count(*) from books";try {pstmt=conn.prepareStatement(sql);result=pstmt.executeQuery();result.next();recordCount=result.getInt(1);t1=recordCount%5;t2=recordCount/5;} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{jdbc.close(conn, pstmt, result);}if(t1 != 0){t2=t2+1;}return t2;}/*** 查询指定页的数据* @param pageNo* @return*/public List<User> listUser(int pageNo){PreparedStatement pstmt=null;ResultSet result=null;List<User> list=new ArrayList<User>();int pageSize=5;int page=(pageNo-1)*5;JDBCUtils jdbc=new JDBCUtils();Connection conn=jdbc.connect();String sql="select * from books order by id limit ?,?";try {pstmt=conn.prepareStatement(sql);pstmt.setInt(1, page);pstmt.setInt(2, pageSize);result=pstmt.executeQuery();while(result.next()){User user=new User();user.setId(result.getInt(1));user.setName(result.getString(2));user.setNumber(result.getString(3));list.add(user);}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}finally{jdbc.close(conn, pstmt, result);}return list;}}User 类⽤于存储查询到的数据,核⼼代码如下:public class User {private int id;private String name;private String number;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) { = name;}public String getNumber() {return number;}public void setNumber(String number) {this.number = number;}}2.控制层ListUser 类内部调⽤ UserDao 对象查询数据并指派页⾯显⽰数据,核⼼代码如下:import java.io.IOException;import java.io.PrintWriter;import java.util.ArrayList;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import er;import erDao;public class ListUser extends HttpServlet {public ListUser() {super();}public void destroy() {super.destroy(); // Just puts "destroy" string in log// Put your code here}public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doPost(request, response);}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setCharacterEncoding("utf-8");int pageNo = 1;UserDao userdao=new UserDao();List<User> lists=new ArrayList<User>();String pageno=request.getParameter("pageNos");if(pageno != null){pageNo=Integer.parseInt(pageno);}lists=userdao.listUser(pageNo);int recordCount=userdao.getPage();request.setAttribute("recordCount", userdao.getPage());request.setAttribute("listss", lists);request.setAttribute("pageNos", pageNo);request.getRequestDispatcher("userlist.jsp").forward(request, response);}public void init() throws ServletException {// Put your code here}}3.表⽰层输出页⾯ userlist.jsp ,使⽤ EL 和 JSTL 输出查询结果,核⼼代码如下:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib prefix="c" uri="/jsp/jstl/core" %><%@ taglib uri="/jsp/jstl/fmt" prefix="fmt"%><%@ taglib uri="/jsp/jstl/functions" prefix="fn"%><%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 'userlist.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">--><style type="text/css">th,td{width: 150px;border: 2px solid gray;text-align: center;}body{text-align: center;}a{text-decoration: none;}table {border-collapse: collapse;}</style></head><body><h2 align="center">图书信息</h2><table align="center"><tr><td>书号</td><td>书名</td><td>库存量</td></tr></table><table align="center"><c:forEach items="${listss}" var="person"><tr><td class="hidden-480">${person.id}</td><td class="hidden-480">${ }</td><td class="hidden-480">${person.number }</td></tr></c:forEach></table><br><c:if test="${pageNos>1 }"><a href="ListUser?pageNos=1" >⾸页</a><a href="ListUser?pageNos=${pageNos-1 }">上⼀页</a></c:if><c:if test="${pageNos <recordCount }"><a href="ListUser?pageNos=${pageNos+1 }">下⼀页</a><a href="ListUser?pageNos=${recordCount }">末页</a></c:if><form action="ListUser"><h4 align="center">共${recordCount}页  <input type="text" value="${pageNos}" name="pageNos" size="1">页<input type="submit" value="到达"></h4></form></body></html>以上所述是⼩编给⼤家介绍的Java Web 简单的分页显⽰实例代码,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
【网页特效代码-页面特效】模拟静态网页分页的特效代码.txt41滴水能穿石,只因为它永远打击同一点。42火柴如果躲避燃烧的痛苦,它的一生都将黯淡无光。"-//W3C//DTD HTML 4.0 Transitional//EN"> New Document header footer