searchresults.jsp
上传用户:junmaots
上传日期:2022-07-09
资源大小:2450k
文件大小:2k
- <%@page contentType="text/html; charset=GBK" language="java" %>
- <%@page import="com.mycompany.news.service.NewsService"%>
- <%@page import="com.mycompany.news.dao.impl.*"%>
- <%@page import="com.mycompany.news.dto.*"%>
- <%@page import="java.util.List"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <link href="./css/common.css" rel="stylesheet" type="text/css">
- <meta http-equiv="Content-Type" content="text/html; charset=gbk">
- <title>新闻查询列表</title>
- </head>
-
- <%
- String keyword = request.getParameter("keyword");
- int pageNo= 1;
- try{
- pageNo=Integer.parseInt(request.getParameter("pageNo"));
- }catch(Exception e){
- }
- int pageSize = 20;
- NewsService service = new NewsService();
- List results = service.search(keyword,pageNo,pageSize);
- System.out.println("results ="+results);
- int totalCount = service.searchCount(keyword);
- int totalPage = totalCount/pageSize+(totalCount%pageSize==0?1:0);
- if(totalCount==0){
- %>
- <script>
- alert('没有找到相应新闻');
- history.go(-1);
- </script>
- <%}
- %>
- <body leftmargin="40">
- <table align="left" border=1 width="90%" bgcolor=#EFEFEF>
- <tr>
- <th width="20%">新闻时间</th>
- <th width="70%">标题</th>
- <th width="10%">作者</th>
- </tr>
- <%for(int i=0;i<results.size();i++){
- News news =(News)results.get(i);
- %>
- <tr>
- <td><%=news.getShowTime()%></td>
- <td><a href="shownews.jsp?id=<%=news.getNewsId()%>" target="_blank"><%=news.getSubject()%></td>
- <td><%=news.getAuthor()%></td>
- </tr>
- <%}%>
- </table>
- <table>
- <tr>
- <td colspan="3" align="right">
- <%if(pageNo>1){%>
- <a href="searchresult.jsp?keyword=<%=keyword%>&pageNo=1">第一页</a>
- <a href="searchresult.jsp?keyword=<%=keyword%>&pageNo=<%=pageNo-1%>">上一页</a>
- <%}%>
- <%if(pageNo<totalPage){%>
- <a href="searchresult.jsp?keyword=<%=keyword%>&pageNo=<%=pageNo+1%>">下一页</a>
- <a href="searchresult.jsp?keyword=<%=keyword%>&pageNo=<%=pageNo+1%>">最后页</a>
- <%}%>
- </td>
- </tr>
- </table>
- </body>
- </html>