JSP: Use request to add static data to a page.

Source: Internet
Author: User

One, insert the data you want to display in the div!

1, the following is the original page insert data code:

<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, create the servlet class in SRC:

Sending data using Request.setattribute

 Public StaticArraylist<string>list; Static{List=NewArraylist<string>(); Listdc.add ("dcrewrwe3eeeeeeeeeeeeeeeee");
Listdc.add ("dcrewrwe3eeeeeeeeeeeeeeeee");
Listdc.add ("dcrewrwe3eeeeeeeeeeeeeeeee");
Listdc.add ("dcrewrwe3eeeeeeeeeeeeeeeee");
Listdc.add ("dcrewrwe3eeeeeeeeeeeeeeeee");
   Public StaticArraylist<string>Listdc; Static{LISTDC=NewArraylist<string>(); Listdc.add ("Dcrewrwe3eeeeeeeeeeeeeeeee"); Listdc.add ("Dcrewrwe3eeeeeeeeeeeeeeeee"); Listdc.add ("Dcrewrwe3eeeeeeeeeeeeeeeee"); Listdc.add ("Dcrewrwe3eeeeeeeeeeeeeeeee"); Listdc.add ("Dcrewrwe3eeeeeeeeeeeeeeeee"); } Public voiddoget (httpservletrequest request, httpservletresponse response)throwsservletexception, 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. Add the JSP script where you want to insert the data:

Using Request.getattribute to receive data

Printing data with A For loop

<Div>                                    <ulclass= "List-content">                                                                                <%ArrayList<String>List=(ArrayList<String>) Request.getattribute ("New"); if(list!=NULL)                                                    for(intI=0; I<list.size (); I++){                                           %>                                                      <Li>                                                          <ahref=""style= "width:644px">                                                            <%Out.print (List.get (i));%>                                                          </a><span>[06-29] </span>                                                      </Li>                                           <%     }%>                                    </ul>                                </Div>                                <Div>                                    <ulclass= "List-content">                                        <%ArrayList<String>LISTDC=(ArrayList<String>) Request.getattribute ("DC"); if(listdc!=NULL)                                            for(intI=0; I<listdc.size (); I++){                                        %>                                        <Li>                                        <ahref=""style= "width:644px">                                        <%Out.print (Listdc.get (i));%>                                        </a><span>[06-29]</span>                                        </Li>                                        <% } %>                                    </ul>                                </Div>

JSP: Use request to add static data to a page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.