遇到一个问题 分页查询后 如何实现编辑功能
<%
request.setCharacterEncoding("UTF-8");//设置编码
String strPageNum = request.getParameter("pageNum");//获得当前页数
int pageNum = 1;
//把当前页数的字符串转换为数字,如果失败则为1,即首页
try{
pageNum = Integer.parseInt(strPageNum);
}catch(Exception e){
pageNum = 1;
}
request.setAttribute("pageNum", pageNum);
ShowAllSongs showAllsongs = new ShowAllSongs();//实例化
showAllsongs.setCountRow();//设置总行数
showAllsongs.setCountPage();//设置总页数
int countPage = showAllsongs.getCountPage();//获得总页数
//如果当前页数小于 0 或者大于总页数,则把当前页重新设置为1
if(pageNum<=0 || pageNum>countPage){
pageNum = 1;
}
showAllsongs.setCurrentlyPage(pageNum);//设置当前页
int currentlyPage = showAllsongs.getCurrentlyPage();//获得当前页
List<Songs> songList = showAllsongs.getSongsPaginQuery(pageNum);
//分页查询
if(songList!=null){
%>
<table border="1" align="center">
<tr>
<td colspan="8">
歌曲名称:<input type="textbox"/><input type="button" value="查找"/>
<input type="button" value="编辑歌曲信息"/>
</td>
</tr>
<tr>
<th align="center">歌曲名称</th>
<th align="center">歌曲编号</th>
<th align="center">分类编号</th>
<th align="center">歌手</th>
<th align="center">加入时间</th>
<th align="center">频道</th>
<th align="center">点击率</th>
<th aling="center">操作</th>
</tr>
<%
for(int i = 0;i<songList.size();i++){
Songs songs = songList.get(i);
%>
<tr>
<td width="150"><%=songs.getTitle() %></td>
<td width="100"><%=songs.getSongid() %></td>
<td width="50"><%=songs.getTypeid() %></td>
<td width="100"><%=songs.getSinger() %></td>
<td width="100"><%=songs.getDateandtime() %></td>
<td width="50"><%=songs.getChannel() %></td>
<td width="100"><%=songs.getHits() %></td>
<td width="100" align="center"><input type="button" value="编辑" src="/servelet/editSongInfo"/></td>
</tr>
<%
}
%>
<tr>
<td colspan="8" align="center">
<%
if(currentlyPage==1){
%>
共<%=countPage %>页
当前第<%=currentlyPage %>页
<a href="showAllSongList.jsp?pageNum=1">首页</a>
上一页
<a href="showAllSongList.jsp?pageNum=<%=currentlyPage+1 %>">下一页</a>
<a href="showAllSongList.jsp?pageNum=<%=countPage %>">尾页</a>
<%
}else if(currentlyPage==countPage){
%>
共<%=countPage %>页
当前第<%=currentlyPage %>页
<a href="showAllSongList.jsp?pageNum=1">首页</a>
<a href="showAllSongList.jsp?pageNum=<%=currentlyPage-1 %>">上一页</a>
下一页
尾页
<%
}
%>
</td>
</tr>
</table>
<%
}else{
%>
<h2 align="center">对不起,没有相应的信息......</h2>
<%
}
%>
如图 数据是 循环出来的 要跳转到编辑页面 值怎么 传过去?
朋友说 循环的时候把值负到按钮上。
可是 我想不出来具体怎么做。
求大大点拨我一下 我是新手。
[最优解释]
songs.getSongid() 这个是不是主键呀
如果是,那就传它到你的编辑事件中去,这样你就知道要修改那个歌曲啦
[其他解释]
<td width="100" align="center"><input type="button" value="编辑" src="/servelet/editSongInfo?id=<%=songs.getSongid() %>"/></td>
你试试这样写。在servlet接受的时候通过request得到id的值 在做相应的处理。
[其他解释]
写个事件,点击时把ID传过去
[其他解释]
循环输出的,点击时怎么取到 当前行的数据?
[其他解释]
你是怎么循环的,例: onclick(${b.id})
[其他解释]
不好意思,没看到上面的代码!你取songs里面的ID就行啊