Read data from the background to <s:select> in Struts2

Source: Internet
Author: User

See online a lot of struts2 from the background to read data to <s:select>, but are not too detailed, may be I can not understand it! So I made a myself, which may have a lot of bad places, look at the vast number of netizens pointed out

Results

 Public classBooksImplementsjava.io.Serializable {// Fields    PrivateString bookId; PrivateString BookType; PrivateString BookName; PrivateString Bookauthor; PrivateString bookpress; PrivateFloat Bookprice; PrivateInteger Booknumber; PrivateSet readers =NewHashSet ();//omit the corresponding set and get methods}


In Impl

// query all book types     Public List Findbooktype ()    {        = hibernatesessionfactory.getsession ();         = session.begintransaction ();        String hql= "from Books GROUP by BookType";         = Session.createquery (hql);         = query.list ();         return list;    }

In action

 Publicstring Findbooktype () {string result= "Error"; List List=NULL; Booksdao Booksdao=NewBooksimpl (); List=Booksdao.findbooktype (); if(list!=NULL) {Actioncontext CTX=Actioncontext.getcontext (); Map Map=ctx.getsession (); Map.put ("BookType", list); //result= "error";SYSTEM.OUT.PRINTLN ("--->" +list.size ()); }                    returnresult; }

In JSP

<label= "category"  name= "Books.booktype"  list= "# Session.booktype "                            listKey=" id "  listvalue=" BookType "  Headerkey= "-1"  headervalue= "Please select the category of the book"                            emptyoption= " False "/>

Struts2 reads data from the background to <s:select>

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.