一,在div中插入要显示的数据!1,以下是原网页插入数据代码:div ul class="list-content"lia href=""aaaaaaaaaaaaaaaaaaa<...
一,在div中插入要显示的数据!
1,以下是原网页插入数据代码:
<div>
<ul class="list-content">
<li><a href="">aaaaaaaaaaaaaaaaaaa</a><span>[06-29]</span></li>
<li><a href="">aaaaaaaaaaaaaaaaaaa</a><span>[06-29]</span></li>
<li><a href="">aaaaaaaaaaaaaaaaaaa.</a><span>[06-29]</span></li>
<li><a href="">aaaaaaaaaaaaaaaaaaa</a><span>[06-29]</span></li>
<li><a href="">aaaaaaaaaaaaaaaaaaa.</a><span>[06-29]</span></li>
<ul>
<div>
<div>
<ul class="list-content">
<li><a href="">aaaaaaaaaaaaaaaaaaa</a><span>[06-29]</span></li>
<li><a href="">aaaaaaaaaaaaaaaaaaa</a><span>[06-29]</span></li>
<li><a href="">aaaaaaaaaaaaaaaaaaa...</a><span>[06-29]</span></li>
<li><a href="">aaaaaaaaaaaaaaaaaaa</a><span>[06-29]</span></li>
<li><a href="">aaaaaaaaaaaaaaaaaaa...</a><span>[06-29]</span></li>
<ul>
</div>
2,在src中创建servlet类:
使用request.setAttribute发送数据
public static ArrayList<String> list;
static{
list=new ArrayList<String>();
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
public static ArrayList<String> listdc;
static{
listdc=new ArrayList<String>();
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
ArrayList<String>list=getData();
request.setAttribute("new", list);
request.setAttribute("dc", listdc);
request.getRequestDispatcher("/page/default.jsp").forward(request, response);
}
3,在需要插入数据的地方加入jsp脚本:
使用request.getAttribute接收数据
通过for循环打印数据
<div>
<ul class="list-content">
<%
ArrayList<String> list =(ArrayList<String>)request.getAttribute("new");
if(list!=null)
for(int i=0;i<list.size();i++){
%>
<li>
<a href="" style=" rel="external nofollow" rel="external nofollow" width:644px">
<% out.print(list.get(i)); %>
</a><span>
[06-29]
</span>
</li>
<% }%>
</ul>
</div>
<div>
<ul class="list-content">
<%ArrayList<String> listdc=(ArrayList<String>)request.getAttribute("dc");
if(listdc!=null)
for(int i=0;i<listdc.size();i++){
%>
<li>
<a href="" style=" rel="external nofollow" rel="external nofollow" width:644px">
<% out.print(listdc.get(i)); %>
</a><span>
[06-29]</span>
</li>
<% } %>
</ul>
</div>
以上这篇jsp 使用request为页面添加静态数据的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
沃梦达教程
本文标题为:jsp 使用request为页面添加静态数据的实例
基础教程推荐
猜你喜欢
- Java实现线程插队的示例代码 2022-09-03
- java基础知识之FileInputStream流的使用 2023-08-11
- springboot自定义starter方法及注解实例 2023-03-31
- Java并发编程进阶之线程控制篇 2023-03-07
- Java文件管理操作的知识点整理 2023-05-19
- JDK数组阻塞队列源码深入分析总结 2023-04-18
- Java数据结构之对象比较详解 2023-03-07
- ConditionalOnProperty配置swagger不生效问题及解决 2023-01-02
- Java实现查找文件和替换文件内容 2023-04-06
- java实现多人聊天系统 2023-05-19