jsp网站工程中,点击查询按钮通过后台sql函数如何将查询结果以表格方式返回到主页面上,详见下图谢谢指导

点击查询按钮,将一个id号传给后台程序,下面是关键代码。*******************************************<tr><tdheight=... 点击查询按钮,将一个id号传给后台程序,下面是关键代码。
*******************************************
<tr> <td height="39"><label for="textfield"></label> <form action="login?arg=3" method="post" id=3> <input type="text" name="ID" id="textfield" width="150" /> <input type="button" name="search" id="button" value="查找" /></td> </form> </tr>
*********************************************
然后是后台处理程序,将会转向case 3.
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException{ int arg = Integer.parseInt(req.getParameter("arg")); switch(arg){ case 1: this.matchUser(req,resp); break; case 2: this.matchManager(req, resp); break; case 3: this.serchByLabelID(req,resp); break; } }
**************************************************************
然后是serchByLabelID函数:
protected void serchByLabelID(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException{ DataDao dataDao = new DataDao(); String labelID = req.getParameter("ID"); ArrayList<Event> list = dataDao.getMatchedEvent(labelID); req.setAttribute("eventList", list); RequestDispatcher rdt = req.getRequestDispatcher("main.jsp"); rdt.forward(req,resp); }
***************************************************************
请问如何通过这种方法将查询到的表格返回到主界面上并能显示出来?谢谢指导。
其他部分没贴出来的代码都已经能实现了,没有问题,我只是想知道如何显示表格这一部分
展开
 我来答
Linn
2015-01-24 · 超过71用户采纳过TA的回答
知道小有建树答主
回答量:131
采纳率:0%
帮助的人:45.8万
展开全部
用jstl标签
<table>
<c:forEach items="${eventList}" var="event" varStatus="status">
<tr>

<td>${event.字段1}</td>

<td>${event.字段2}</td>
.....

</tr>

</c:forEach>
</table>
${status.index}是序号,从0开始。
追问
这个req和这些语句有什么联系,麻烦解释一下
追答
req.setAttribute("eventList", list);你把list放到req中带回,通过${eventList}就可以取到你放到attribute中的list。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式