显示关键字泛红

            <%
                String search = null;
                    String stu = request.getParameter("stu");
                    String select_stu = request.getParameter("select_stu");
                    select_stu=new String(select_stu.getBytes("ISO-8859-1"),"utf-8");
                    if ("Xno".equals(stu)) {
                        search = (String) request.getAttribute("s_no"); // 显示的内容      
                    } else if ("Xname".equals(stu)) {
                        search = (String) request.getAttribute("s_name"); // 显示的内容                              
                    } else if ("Xmajor".equals(stu)) {
                        search = (String) request.getAttribute("s_major"); // 显示的内容      
                    }
                    
                    String searchWord = select_stu; //要替换的关键词
                    search = search.replaceAll(searchWord, "<font color='#FF0000'>"
                            + searchWord + "</font>");// 从search 中找到 searchWord 把他替换
                            
            %>
            <%=search%>

 

posted @ 2012-11-05 01:23  hlb  阅读(192)  评论(0编辑  收藏  举报