è¶ é¾æ¥å¨JSP
问题描述:
我使用JSP来从MySQL数据库的影片名称和浏览器中显示它的谷歌搜索。我想让这个名字成为一个超链接,点击这个链接会导致谷歌搜索那部电影。超链接在JSP
<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
答
你可以试试这个:
String name = rs.getString("title");
out.println("<a href=\"https://www.google.co.in/search?q="+name+"\">"+name+"</a>");
你确定之前,一个单引号
对不起,我是一个PHP的家伙,只是想帮助。让我更新。 – Manikiran