Action in the ArrayList display to the JSP page specific instance _jsp programming

Source: Internet
Author: User
Tags commit

The ArrayList object obtained in Useraction is populated into UserForm, and the JSP page gets the initial value of UserForm.
Part of Useraction code:

Copy Code code as follows:

Private Actionforward executemanageaction (actionmapping mapping, Actionform form,
HttpServletRequest request, HttpServletResponse response) {
UserForm UserForm = (UserForm) Form;
ArrayList userlist = new ArrayList ();
Sessionfactory sf= New Configuration (). Configure (). Buildsessionfactory ();
Session session=sf.opensession ();
Transaction tx=session.begintransaction ();
String sqlquery= "from User";
Query lquery=session.createquery (sqlquery);
Userlist= (ArrayList) lquery.list ();
Tx.commit ();
Session.close ();
Userform.setuserlist (userlist);
Return Mapping.findforward ("Main_user");
}

Part of Usrform code:
Copy Code code as follows:

Private ArrayList userlist;
Public ArrayList getuserlist () {
return userlist;
}
public void Setuserlist (ArrayList userlist) {
This.userlist=userlist;
}

JSP page code:
Copy Code code as follows:

<table id= "Id1" style= "Border-right:darkgreen 1px solid;border-top:darkgreen 1px solid;border-left:darkgreen 1px solid;width:100%;
Border-bottom;darkgreen 1px solid;border-collapse:collapse "bordercolor=" Darkgreen "cellspacing=" 0 "border=" 1 ">
<logic:notempty name= "UserForm" property= "UserList" >
<tr nowrap= "nowrap" >
&LT;TD style= "width:80px;height:16px" nowrap><b> username </b></td>
&LT;TD style= "width:80px;height:16px" nowrap><b> role </b></td>
&LT;TD style= "width:84px;height:16px" ><b> name </b></td>
&LT;TD style= "WIDTH:88PX;HEIGHT:16PX" ><b> Tel </b></td>
&LT;TD style= "width:73px;height:16px" ><b> email </b></td>
&LT;TD style= "width:273px;height:16px" ><b> action </b></td>
</tr>
<logic:iterate indexid= "index" id= "user" Name= "UserForm" property= "UserList" >
<tr>
&LT;TD noWrap style= "width:80px" ><bean:write name= "user" property= "username"/></td>
&LT;TD noWrap style= "width:80px" ><bean:write name= "user" property= "role"/></td>
&LT;TD noWrap style= "width:80px" ><bean:write name= "user" property= "name"/></td>
&LT;TD noWrap style= "width:80px" ><bean:write name= "User" property= "tel"/></td>
&LT;TD noWrap style= "width:80px" ><bean:write name= "user" property= "email"/></td>
&LT;TD nowrap sryle= "width:273px" >
<a href= "Javascript:submitsid (Document.fview, ' <bean:write name=" user "property=" username "/> ')" > View < /a>
<font >| | </font>
<a href= "Javascript:submitsid (Document.fview, ' <bean:write name=" user "property=" username "/>") "> Update < /a>
<font >| | </font>
<a href= "javascript:if confirm (' Delete this user? ')} {submitsid (Document.fview, ' <bean:write name= "user" property= "username"/> ')} "> Delete </a>
</td></tr>
</logic:iterate>
</logic:notEmpty>
</table>

after acquiring the data ArrayList object in Useraction, the ArrayList object exists in request, and the JSP page obtains the ArrayList object.
Useraction part of the code:
Copy Code code as follows:

Private Actionforward executemanageaction (actionmapping mapping, Actionform form,
HttpServletRequest request, HttpServletResponse response) {
UserForm UserForm = (UserForm) Form;
ArrayList userlist = new ArrayList ();
Sessionfactory sf= New Configuration (). Configure (). Buildsessionfactory ();
Session session=sf.opensession ();
Transaction tx=session.begintransaction ();
String sqlquery= "from User";
Query lquery=session.createquery (sqlquery);
Userlist= (ArrayList) lquery.list ();
Tx.commit ();
Session.close ();
Request.setattribute ("UserList", userlist);
Return Mapping.findforward ("Main_user");
}

JSP Part code:
Copy Code code as follows:

<table id= "Id1" bordercolor= "Darkgreen" cellspacing= "0" border= "1" >
<tr >
&LT;TD ><b> User Name </b></td>
&LT;TD ><b> Role </b></td>
&LT;TD ><b> name </b></td>
&LT;TD ><b> Tel </b></td>
&LT;TD ><b> Email </b></td>
&LT;TD ><b> Action </b></td>
</tr>
<logic:present name= "UserList" >
<logic:iterate indexid= "index" id= "user" name= "userlist" >
<tr>
&LT;TD ><bean:write name= "user" property= "username"/></td>
&LT;TD ><bean:write name= "user" property= "role"/></td>
&LT;TD ><bean:write name= "user" property= "name"/></td>
&LT;TD ><bean:write name= "User" property= "tel"/></td>
&LT;TD ><bean:write name= "user" property= "email"/></td>
&LT;TD >
<a href= "Javascript:submitsid (Document.fview, ' <bean:write name=" user "property=" username "/> ')" > View < /a>
<font >| | </font>
<a href= "Javascript:submitsid (Document.fview, ' <bean:write name=" user "property=" username "/>") "> Update < /a>
<font >| | </font>
<a href= "javascript:if confirm (' Delete this user? ')} {submitsid (Document.fview, ' <bean:write name= "user" property= "username"/> ')} "> Delete </a>
</td></tr>
</logic:iterate>
</logic:present>
</table>

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.