打关键字就连接到百度上去了,而不是本站搜索,不知道哪里出了问题:<%@ page pageEncoding="gb2312" language="java" import="java.sql.*" errorPage="err.jsp?msg=错误!" %>
<%@ include file="conn.jsp"%>
<%request.setCharacterEncoding("gb2312");
 response.setContentType("text/html;charset=GB2312"); 
String keywords=request.getParameter("k").trim();
//keywords=keywords.getBytes("gb2312");
String sql="select num=count(*) from download where softname like '%"+keywords+"%' or note like '%"+keywords+"%'";
ResultSet rs=stmt.executeQuery(sql);
//out.print(sql);
rs.next();
int intRowCount;
intRowCount=rs.getInt("num");
//out.print(intRowCount);
if(intRowCount==0){
//keywords=new String(keywords.getBytes("gb2312"),"UTF-8");
String gourl="http://www.baidu.com/baidu?ct=0&ie=gb2312&bs=%B3%C7%CA%D0&wd="+keywords+"&cl=3&f=8";
//out.print(gourl);
response.sendRedirect(gourl);
}else{
//request.setCharacterEncoding("gb2312");
Statement stmt2=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql2="select * from class";
ResultSet rs2=stmt2.executeQuery(sql2);
int intPageCount;//初始页数
int intPageSize;//初始页面大小
//int intRowCount;//初始记录数
int intPage;//初始页号
int i,j;
String pageno=request.getParameter("page");
if(pageno==null){
intPage=1;
 }else{
  intPage=Integer.parseInt(pageno);
  if(intPage<1){
  intPage=1;
  }
 }
intPageSize=20;
intPageCount=(intRowCount+intPageSize-1) / intPageSize;if(intPage>intPageCount)
{ intPage=intPageCount;}
 
Statement stmt4=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql4="select a.id,a.softname,a.downurl,a.urlsay,a.softsize,a.codeshow,a.abouturl,a.images,a.sq,a.lang,a.tj,a.jp,a.jb,a.note,a.hits,a.yxhj,a.grade,a.addtime,classid=a.classid,class=b.class from download as a inner join class as b on a.classid=b.classid where a.softname like '%"+keywords+"%' or a.note like '%"+keywords+"%' order by a.addtime Desc";
ResultSet rs4=stmt4.executeQuery(sql4);
//out.print(intPage);
i=(intPage-1)*intPageSize;
for(j=0;j<i;j++)
{rs4.next();
//out.print(i);
//out.print("<br>");
}%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    </HTML>
      网页部分!!
    </HTML>
<%
rs4.close();
stmt4.close();
conn.close();
}
rs.close();
stmt.close();
%>

解决方案 »

  1.   

    我不知道你是不是想输入关键字后,点击搜索到百度中关于这个关键字的列表??如果是这样的话,只用加一个超链接就可以了
    方法:<a href="http://www.baidu.com/s?ie=utf-8&wd=关键字&cl=3">关键字</a>
      

  2.   

    <form name=f action="http://www.baidu.com/s" onsubmit="DynamicForm.submit();return false;">
    <td><a id="hao_img_logo"  href="http://www.baidu.com"></td>
    <td width="373px"><noscript><input  type="hidden" name="tn" value="sitehao123"></noscript>
    <div id="sugOut"><input value="" name="wd" maxlength=100 id="kww" autocomplete="off">
    <br><div id="sug" ></div></div></td>
    <td><button type="submit">百度一下</button></td></form>很多网站上都有这样的功能,上面这段HTML代码来自hao123.com。照着写就行了。