您现在的位置是:网站首页> 编程资料编程资料

jsp 使用request为页面添加静态数据的实例_JSP编程_

2023-05-25 539人已围观

简介 jsp 使用request为页面添加静态数据的实例_JSP编程_

一,在div中插入要显示的数据!

1,以下是原网页插入数据代码:

2,在src中创建servlet类:

使用request.setAttribute发送数据

 public static ArrayList list; static{ list=new ArrayList(); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee"); listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");    public static ArrayList listdc; static{ listdc=new ArrayList(); 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"); ArrayListlist=getData(); request.setAttribute("new", list); request.setAttribute("dc", listdc); request.getRequestDispatcher("/page/default.jsp").forward(request, response); }

3,在需要插入数据的地方加入jsp脚本:

使用request.getAttribute接收数据

通过for循环打印数据

以上这篇jsp 使用request为页面添加静态数据的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

-六神源码网