一,在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 ArrayListString> list;
static{
list=new ArrayListString>();
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
listdc.add("dcrewrwe3eeeeeeeeeeeeeeeee");
public static ArrayListString> listdc;
static{
listdc=new ArrayListString>();
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");
ArrayListString>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">
%
ArrayListString> list =(ArrayListString>)request.getAttribute("new");
if(list!=null)
for(int i=0;ilist.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">
%ArrayListString> listdc=(ArrayListString>)request.getAttribute("dc");
if(listdc!=null)
for(int i=0;ilistdc.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为页面添加静态数据的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:- SpringMVC 向jsp页面传递数据库读取到的值方法
- jsp实现textarea中的文字保存换行空格存到数据库的方法
- Struts2.5 利用Ajax将json数据传值到JSP的实例
- JSP 自定义标签实现数据字典的实例
- 读取数据库的数据并整合成3D饼图在jsp中显示详解
- springMVC如何将controller中数据传递到jsp页面
- jsp中EL表达式获取数据
- JSP数据交互实现过程解析