struts2中把查询出来的数据如何通过jsp显示
action的方法:
/**
*修改信息的方法使页面跳转到相应的页面
*/
public String modify(){
HttpServletRequest request=ServletActionContext.getRequest();
String positionId=request.getParameter("roleId");
//System.out.println("前台传过来的Id:"+positionId);
String hql="from Position p where p.positionId="+positionId;
List<Position> list=positionService.findEntitybyHQL(hql);
request.setAttribute("list",list);
return "modify";
}
jsp:页面
<s:iterator value="#request.list">
<tr height="28px">
<td class="TDBasLabel">职位编号:</td>
<td colspan="1">
<s:textfield name="positionNo" maxlength="16" cssStyle="width:100%;" cssClass="tdTextBox"/>
</td>
<td class="TDLabel">职位类型:</td>
<td colspan="1">
</td>
</tr>
<tr height="28px">
<td class="TDBasLabel">职位名称:</td>
<td colspan="3">
<s:textfield name="positionName" maxlength="30" cssStyle="width:100%;" cssClass="tdTextBox"/>
</td>
</tr>
</s:iterator>
==========================第二种情==================================
action 中方法:
/*
* 页面加载时就执行的方法
*/
@Override
public String execute() throws Exception {
System.out.println("进入这个方法");
HttpServletRequest request=ServletActionContext.getRequest();
List<Position> position = positionService.findEntitybyHQL();
request.setAttribute("position", position);
return SUCCESS;
}
jsp页面:
<s:iterator value="#request.position" status="st">
<tr style="background: <s:if test="#st.odd">#ccffff</s:if><s:else>#ccff99</s:else>" onclick="enterEdit('<s:property value="positionId"/>')">
<td><div align="center"><input type="checkbox" name="checkItems" value="<s:property value="positionId"/>"/></div></td>
<td><div align="center"><s:property value="positionId"/> </div></td>
<td><div align="center"><s:property value="positionNo"/></div></td>
<td><div align="center"><s:property value="positionName"/></div></td>
<td><div align="center"><s:property value="jobClass"/></div></td>
<td><div align="center"><s:property value="workDesc"/></div></td>
<td><div align="center"><s:property value="workDemand"/></div></td>
<td><div align="center"><label onclick="setRoleRights('<s:property value="positionId"/>')"> 权限</label></div></td>
<td><div align="center"></div></td>
</tr>
</s:iterator>