2016-11-19 5 views
1

私はjspを使ってmysql dbからムービー名を取り出してブラウザに表示しています。ハイパーリンクとして名前を付けたいのですが、クリックするとその映画のgoogle検索が行われます。jspのgoogle検索へのハイパーリンク

<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>"); 
     } 

    } 
    %> 

映画の名前をクリックするとgoogle(pref imdb)検索ページが表示されます。画像enter image description here

答えて

0

を参照してくださいあなたはこれを試すことができます。

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

あなたが<(すなわち「

+0

一定の無効な文字を表示する前に、私はPHPの男だ単一引用符について確信しています、ちょうど助けようとしている。私に更新させてください。 – Manikiran