jsp 使用request为页面添加静态数据的实例
一,在div中插入要显示的数据!
1,以下是原网页插入数据代码:
aaaaaaaaaaaaaaaaaaa[06-29] aaaaaaaaaaaaaaaaaaa[06-29] aaaaaaaaaaaaaaaaaaa.[06-29] aaaaaaaaaaaaaaaaaaa[06-29] aaaaaaaaaaaaaaaaaaa.[06-29]
aaaaaaaaaaaaaaaaaaa[06-29] aaaaaaaaaaaaaaaaaaa[06-29] aaaaaaaaaaaaaaaaaaa...[06-29] aaaaaaaaaaaaaaaaaaa[06-29] aaaaaaaaaaaaaaaaaaa...[06-29]
2,在src中创建servlet类:
使用request.setAttribute发送数据
publicstaticArrayListlist; static{ list=newArrayList (); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); publicstaticArrayList listdc; static{ listdc=newArrayList (); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); } publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse) throwsServletException,IOException{ request.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); ArrayList list=getData(); request.setAttribute("new",list); request.setAttribute("dc",listdc); request.getRequestDispatcher("/page/default.jsp").forward(request,response); } 3,在需要插入数据的地方加入jsp脚本:
使用request.getAttribute接收数据
通过for循环打印数据
<% ArrayList list=(ArrayList )request.getAttribute("new"); if(list!=null) for(inti=0;i - <%}%>
<%out.print(list.get(i));%> [06-29] <%ArrayList listdc=(ArrayList )request.getAttribute("dc"); if(listdc!=null) for(inti=0;i - <%}%>
<%out.print(listdc.get(i));%> [06-29] 以上这篇jsp使用request为页面添加静态数据的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 元宵贺卡祝福语结婚简短11 早日回国祝福语简短英语12 婚礼结束聚餐祝福语简短13 见证求婚文案祝福语简短14 接亲新郎进门祝福语简短15 最美母女祝福语简短英文16 喜得新房文案祝福语简短17 学生开心成语祝福语简短18 婚礼西装祝福语简短男士