日期:2014-05-17 浏览次数:20693 次
<%@page language="java" import="java.util.*,bbs.*,java.sql.*"%> <%@page pageEncoding="UTF-8"%> <% request.setCharacterEncoding("UTF-8"); String value = request.getParameter("title"); %> <% List<Article> articles = new ArrayList<Article>(); Connection conn = DB.getConn(); Statement stmt = DB.createStmt(conn); //System.out.println(value); String sql = "select * from article where title like '%"+value+"%'"; //System.out.println(sql); ResultSet rs = DB.executeQuery(stmt, sql); String str =""; while (rs.next()) { Article a = new Article(); a.initFromRs(rs); articles.add(a); } %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>搜索结果</title> </head> 搜索结果:<br> <% for (Iterator<Article> it = articles.iterator(); it.hasNext();) { Article a = it.next(); %> <body> <a href="articleDetailFlat.jsp?id=<%=a.getId()%>"><%=a.getTitle()%></a> <br> </body> <%} %> </html>
<% int index = a.getTile().indexOf(value); %> <a href="articleDetailFlat.jsp?id=<%=a.getId()%>"> <%=a.getTitle().substring(0, index)%><font color=xxx><%=value></font><%=a.getTitle().substring(index+1) </a>