struts2中怎么样将已经查询到的LIST显示到jsp页面中,急!
通过JSP页面传递过来的关键字,查询数据库,返回查询结果给一个list,怎么样将其显示到JSP的表格中以及通过控制台输出这个list的值。
源码如下:
StuFindAction.java //学生信息查询模块
package com.cs.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.cs.dao.IUserDao;
import com.cs.model.TblStudentinfo;
import com.cs.service.IUserService;
/**
* 学生查询模块
*
* @author Administrator
*/
@SuppressWarnings("serial")
public class StuFindAction extends AbstractActionSupport
{
private TblStudentinfo user;
private IUserService userservice;
private IUserDao userdao;
private List<TblStudentinfo> Stuinfo;
public void setUserdao(IUserDao userdao)
{
this.userdao = userdao;
}
public TblStudentinfo getUser()
{
return user;
}
public void setUser(TblStudentinfo user)
{
this.user = user;
}
public void setUserservice(IUserService userservice)
{
this.userservice = userservice;
}
public List<TblStudentinfo> getStuinfo() {
return Stuinfo;
}
public void setStuinfo(List<TblStudentinfo> Stuinfo) {
this.Stuinfo = Stuinfo;
}
/**
* 通过关键字从前台获取选定的学生信息集合,返回到类型为list的Stuinfo中
*/
public String execute() throws Exception
{
HttpServletRequest request = ServletActionContext.getRequest();
String selectStu = request.getParameter("keyword");
Stuinfo = userdao.getStuInfo(selectStu);//Stuinfo通过debug可以看到其中有返回的值
for (int i = 0; i < Stuinfo.size(); i++)
{
request.setAttribute("Stuinfo", Stuinfo.get(i));
//System.out.println(Stuinfo.get(i));这句代码输出到控制台有误,不知怎么输出?
}
//System.out.println(Stuinfo);
return "success";
}
}
在struts.xml中配置如下:
<action name="StuFindAction" class="com.cs.action.StuFindAction">
<result name="success">stuinfofind.jsp</result>