In Action, ArrayList displays the specific instances on the JSP page.

Source: Internet
Author: User

1. Fill in the ArrayList object obtained in UserAction to UserForm, and obtain the initial value of UserForm on the jsp page.
Some code of UserAction:
Copy codeThe Code is 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 ");
}

Some UsrForm code:
Copy codeThe Code is as follows:
Private ArrayList userlist;
Public ArrayList getUserlist (){
Return userlist;
}
Public void setUserlist (ArrayList userlist ){
This. userlist = userlist;
}

JSP page code:
Copy codeThe Code is as follows:
<Table id = "id1" style = "border-right: darkgreen1px 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">
<Td style = "width: 80px; height: 16px" nowrap> <B> User Name </B> </td>
<Td style = "width: 80px; height: 16px" nowrap> <B> role </B> </td>
<Td style = "width: 84px; height: 16px"> <B> name </B> </td>
<Td style = "width: 88px; height: 16px"> <B> telephone </B> </td>
<Td style = "width: 73px; height: 16px"> <B> email </B> </td>
<Td style = "width: 273px; height: 16px"> <B> action </B> </td>
</Tr>
<Logic: iterate indexId = "index" id = "user" name = "userForm" property = "userlist">
<Tr>
<Td noWrap style = "width: 80px"> <bean: write name = "user" property = "username"/> </td>
<Td noWrap style = "width: 80px"> <bean: write name = "user" property = "role"/> </td>
<Td noWrap style = "width: 80px"> <bean: write name = "user" property = "name"/> </td>
<Td noWrap style = "width: 80px"> <bean: write name = "user" property = "tel"/> </td>
<Td noWrap style = "width: 80px"> <bean: write name = "user" property = "email"/> </td>
<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>

2. After obtaining the ArrayList object of data from UserAction, The ArrayList object is stored in the request, and the JSP page obtains the ArrayList object.
Part of the UserAction code:
Copy codeThe Code is 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 ");
}

Part of JSP code:
Copy codeThe Code is as follows:
<Table id = "id1" borderColor = "darkgreen" cellSpacing = "0" border = "1">
<Tr>
<Td> <B> User Name </B> </td>
<Td> <B> role </B> </td>
<Td> <B> name </B> </td>
<Td> <B> phone number </B> </td>
<Td> <B> email </B> </td>
<Td> <B> action </B> </td>
</Tr>
<Logic: present name = "userlist">
<Logic: iterate indexId = "index" id = "user" name = "userlist">
<Tr>
<Td> <bean: write name = "user" property = "username"/> </td>
<Td> <bean: write name = "user" property = "role"/> </td>
<Td> <bean: write name = "user" property = "name"/> </td>
<Td> <bean: write name = "user" property = "tel"/> </td>
<Td> <bean: write name = "user" property = "email"/> </td>
<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.