struts2中select標(biāo)簽的用法總結(jié)
Posted on 2010-10-03 17:06 石子路口 閱讀(3855) 評(píng)論(1) 編輯 收藏 所屬分類: 網(wǎng)頁(yè)制作 、struts2 使用struts2的標(biāo)簽可以大大提高開發(fā)效率,剛剛學(xué)習(xí)了select標(biāo)簽的使用,并成功跟后臺(tái)連接,這里把代碼奉上
功能目的:根據(jù)找到的課程列表,使用select標(biāo)簽選擇課程,并顯示相應(yīng)的欄目
jsp頁(yè)面代碼:
<body>
<s:form name="selectCourse" action="browseColumn.action" method="post">
<table align="center" border="0" width="760">
<tr>
<td align="right" width="100" style="color: #FF2D2D">
課程名:
</td>
<td>
<s:select list="courses" name="courseId" listKey="id" listValue="name"
onchange="selectCourse.submit()" theme="simple"></s:select>
</td>
</tr>
</table>
</s:form>
</body>
說(shuō)明:courses對(duì)應(yīng)于action中的list,courseId為列表中選中項(xiàng)的key值,id和name分別對(duì)應(yīng)于課程類(Kc)的id和name
action類
public class ColumnAction extends ActionSupport
{
//課程id
private String teacherId;
private String courseId;
private List<Kc> courses;
//getter和setter方法
//查詢指定教師所有課程
public String browseCourse()
{
int tId = Integer.parseInt(teacherId);
setCourses(columnService.getCourse(tId));
for(Kc kc:courses)
{
System.out.println("課程號(hào):" + kc.getId() + ", 課程名:" + kc.getName());
}
return SUCCESS;
}
//根據(jù)課程查詢欄目
public String browseColumn() throws Exception
{
System.out.println("課程號(hào):" + courseId );
// setCourseName(columnService.getCourseName(course.getId()));
setColumnBeans(columnService.getColumnByCourse(Integer.parseInt(courseId)));
return SUCCESS;
}
}
struts.xml的配置
<action name="browseCourse" class="columnAction"
method="browseCourse">

<result name="success">/page/teacher/result.jsp</result>
</action>
<action name="browseColumn" class="columnAction"
method="browseColumn">

<result name="success">/page/teacher/result.jsp</result>
</action>
這樣就可以正常顯示了
功能目的:根據(jù)找到的課程列表,使用select標(biāo)簽選擇課程,并顯示相應(yīng)的欄目
jsp頁(yè)面代碼:















action類








































