在jsp中谷歌搜索的超链接

时间:2016-11-19 10:00:44

标签: html jsp

我正在使用jsp从mysql db中获取电影名称并将其显示在浏览器上。我希望将该名称设为超链接,点击后会导致谷歌搜索该电影。

    <html>
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>

    </head>
    <style>
    body {

    background-size:     cover;                      
    background-repeat:   no-repeat;
    background-position:  ;              
    }

   </style>
   <body background="N.jpg">
   <FONT color="#19334d" size="5">

    <p>
   </br>
   <center>
   <b>
   <h2>Top 10 recommendations for you</h3>
   <%

    Class.forName("com.mysql.jdbc.Driver");  
    Connection con =    DriverManager.getConnection("jdbc:mysql://localhost:3306/movies","root","");    
    String encArray = request.getParameter("fib");
    String decArray = URLDecoder.decode(encArray,"utf-8");
    String [] str = decArray.split(",");
    int num[] = new int[10];
    for(int i=0;i<10;i++)
    {
        num[i]=Integer.parseInt(str[i].trim());
    }

    for(int i=0;i<10;i++)
    {
         PreparedStatement ps =con.prepareStatement("Select title from mydatabase where movieid =?");
         ps.setInt(1,num[i]);
         ResultSet rs = ps.executeQuery();
         while(rs.next()){
             String name  = rs.getString("title");

             out.print(i+1 + "->");
             out.println(name);

             out.println("<br>");
             out.println("<br>");
         }

     }
     %>

我想要的是,点击一个电影名称,它应该导致其谷歌(pref imdb)搜索页面。见图像enter image description here

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

String name  = rs.getString("title");
out.println("<a href=\"https://www.google.co.in/search?q="+name+"\">"+name+"</a>");
相关问题