struts2,jspÒ³ÃæÏòactionÌá½»list¶ÔÏó
Struts2
ÖÐÖ§³ÖʹÓÃListÔÚÒ³ÃæºÍActionÖ®¼äÖ±½Ó´«µÝ±í¸ñÊý¾Ý¡£ÏÂÃæÊÇÒ»¸öʾÀý£º
public class Person {
int id;
String name;
int age;
float
height;
}
ÕâÊÇÒ»¸öPOJO£¬getterºÍsettingÊ¡ÂÔÁË¡£
actionÖпÉÒÔÕâÑùʹÓãº
public class MyAction {
public List getPeopleList() { … }
public
void setPeopleList( List peopleList ) { … }
…
}
ÔÚÎÒÃÇʹÓÃPersonÀà֮ǰ£¬ÐèÒªÌí¼ÓÒ»¸öÅäÖÃÎļþ£¬MyAction-conversion.properties£¬°ÑÕâ¸öÎļþºÍMyAction·ÅÔÚÒ»Æð¡£
Õâ¸öÎļþÀïÖ»ÓÐÒ»ÐÐÄÚÈÝ£º
Element_peopleList=Person
ǰ׺Element_ÊÇÒ»¸ö³£Á¿£¬±íÃ÷µÈºÅ×ó±ßµÄ±í´ïʽÖиúÔÚÕâ¸ö³£Á¿ºóÃæµÄÊÇActionÀàÖÐÒ»¸öListÀàÐ͵Ä×Ö¶ÎÃû¡£
µÈºÅÓұߵıí´ïʽÊÇÈ«ÀàÃû£¨°üº¬package£©
ÏÂÃæÊÇÒ»¸öÒ³ÃæµÄ´úÂëÆ¬¶Î£º
<s:form action="update"
method="post" >
<s:iterator value="peopleList" status="stat">
<s:hidden name="peopleList[%{#stat.index}].id"
value="%{peopleList[#stat.index].id}"/>
<s:textfield label="Name"
name="peopleList[%{#stat.index}].name"
value="%{peopleList[#stat.index].name}"/>
<s:textfield label="Age"
name="peopleList[%{#stat.index}].age"
value="%{peopleList[#stat.index].age}" />
<s:textfield
label="Height" name="peopleList[%{#stat.index}].height"
value="%{peopleList[#stat.index].height}"/>
<br/>
</s:iterator>
<s:submit value="Update"/>
</s:form>
ʹÓÃÕâ¶Î´úÂ룬Struts2
»á´´½¨Ò»¸öPersonÀàµÄArrayList£¬²¢ÇÒÓÃsetPersonListÕâ¸ö·½·¨°ÑÒ³Ãæ±í¸ñÖеÄÖµ´«µÝ»ØAction¡£
Èç¹ûÄãÊÇÏë´ÓÓû§½çÃæÖж¯Ì¬´´½¨ÁбíÖµ£¬ÐèÒªÔÊÐíStruts2
¸øÁбíÖÐÀ
Ïà¹ØÎĵµ£º
1.No getter method for property name problem(struts)
ÓÐÒ»ÖÖ¿ÉÄÜÊÇBeanûÓÐдÏàÓ¦µÄget·½·¨£¬ÀýÈç±äÁ¿userNameµÄget·½·¨ÊÇgetUserName£»
»¹ÓоÍÊÇÕâ¸öBeanΪ¿Õ£»
2.
MyEclipseµÄ×Ô¶¯Ìí¼ÓstrutsºÍhibernate¹¦Äܲ»ÄÜ·µ»Ø£¬Çë×¢Ò⣡
ËùÒÔÎÒÏÈʹÓÃMyEclipseµ¼ÈëstrutsºÍhibernate£¬È»ºó½«ËüÃǵÄjarµ¼Èëµ½ÁíÍâÒ»¸öн¨µÄ ......
ÔÚ²»ÔÊÐíĿ¼ä¯ÀÀµÄÇé¿öÏ ä¯ÀÀÆ÷»áÏÈÕÒµ½Ê×Ò³£¨Ä¬ÈÏΪindex.html /index.jsp...£©
·ñÔò³ö´í
Òò´Ë ÈôÊ×Ò³±»¶ñÒâ¸ü¸Ä ÍøÕ¾±ÀÀ£
½â¾ö·½·¨£º
¸ü¸ÄĬÈÏÆô¶¯Ò³Ã棺$tomcat/conf/web.xml×îºóλÖÃ
<welcome-file-list>
<welcome-file>index.html</welcome-file> ......
ÔÚjspÖв»Óö¨Òå¿ÉÒÔÖ±½ÓÓõľÍÊÇjspµÄ9¸öÄÚ½¨¶ÔÏóÁË
1£¬Request 2,Response 3,session 4,out 5,page
6,application 7,pageContext 8,config
9,exception
1¡¢Request¶ÔÏó
¸Ã¶ÔÏó·â×°ÁËÓû§Ìá½»µÄÐÅÏ¢£¬Í¨¹ýµ÷ÓøöÔÏóÏàÓ¦µÄ·½·¨¿ÉÒÔ»ñÈ¡·â×°µÄÐÅÏ¢£¬¼´Ê¹ÓøöÔÏó¿ÉÒÔ
»ñÈ¡Óû§Ìá½»µÄÐÅÏ¢¡£
µ±Request¶ÔÏó»ñÈ¡¿Í» ......