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>