<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script>
var request;
function sendInfo()
{
var url="unlike.jsp";
if(window.XMLHttpRequest){
request=new XMLHttpRequest();
}
else if(window.ActiveXObject){
request=new ActiveXObject("Microsoft.XMLHTTP");
}
try{
request.onreadystatechange=getInfo;
request.open("GET",url,true);
request.send();
}catch(e){alert("Unable to connect to server");}
}
function getInfo(){
if(request.readyState==4){
var val=request.responseText;
document.getElementById('amit').innerHTML=val;
}
}
</script>
</head>
<body>
<% try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/facebook","root","sesame");
PreparedStatement ps=con.prepareStatement("select * from likes ");
ResultSet rs=ps.executeQuery();
while(rs.next()){
out.println("<A HREF=\"unlike.jsp\">unlike</A id="amit"> "+rs.getInt(1));
out.println("people liked this ☻");
}
con.close();
}catch(Exception e){e.printStackTrace(); } %>
</body>
</html>
here i am developing a small "like button" like facebook using ajax and jsp, my problem is i am not able to understand how to write this out.print ---
out.println("<A HREF=\"unlike.jsp\" id="link" onclick="return doalert()>unlike</A> "+rs.getInt(1));
with an id and an onClick function so that when user clicks is i should able to call the unlike.jsp and like.jsp respectively and hide this out.print as required