Servlet accesses JavaBean and passes results to JSP

Source: Internet
Author: User

1. Create the package name first:

2. Creating entity Classes

Refer to the two-dimensional table, consider each field name, type

Create a class in the entity package with the following code:

 Public class House {    private  String ID;     Private String name;     Private String address;      Public String getId () {        return  ID;    }    ... .. // other

3. Establishing the Business Logic interface (Houseservice) and implementation (Houseserviceimpl)

Manager Write Interface: Public InterfaceHouseservice { PublicListgetallhouses ();} Brother Write implementation class: @Override PublicListgetallhouses () {List<House> houselist =NewArraylist(); //1 Bald-headed home forest, number 188th.//2 Bear Big House forest tree hole Phase 3 floorHouse H1 =NewHouse (); House H2=NewHouse (); H1.setid ("1"); H1.setname ("Great place to be."); H1.setaddress ("Forest No. 188th"); H2.setid ("2"); H2.setname ("The home of the Bear"); H2.setaddress ("3/F, forest Tree cave Phase One");        Houselist.add (H1);                Houselist.add (H2); returnhouselist; }

4. Create a (Servlet) controller, call the service Fetch DataSet list "Send the results to the JSP and jump to the past"

Create a new servlet:houseaction_showallhoses in the action package

4. Create a show.jsp to get the list from the Request object

Core code: Request.getattribute ("Houselist_label");

The rest of the code in the reference war package is the same as the previous example.

Servlet accesses JavaBean and passes results to JSP

Related Article

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.