Utilizing JSP to showcase information obtained from user queries, I have implemented a system where contextual data and the query itself are saved in a MySQL database using JDBC each time a new query is input. To enhance user interaction, I wanted to incorporate a rating system that allows users to rate each result by clicking on numbered stars (e.g., ** ***** **** corresponds to 2 5 4). Here is the code snippet from my JDBC:
PreparedStatement preps = null;
preps = dbMySqlConn.prepareStatement("" +
" UPDATE " + dbName + "." + tableNameOutput +
" SET" + " ratings = ?" +
" WHERE id = " + queryID , Statement.RETURN_GENERATED_KEYS);
if (stars != null) {
preps.setString(19, stars);
}
preps.execute();
The visual representation of the rating system in my main JSP file looks like this:
<form name="rating">
<input class="star star-5" id="star" + sessionTime + i + "-5" type="radio" onClick="javascript:saveRating()" name="star"/>
<label class="star star-5" for="star" + sessionTime + i + "-5" title="Perfect match"></label>
</input>
// Other star inputs go here
</form>
This form triggers a JavaScript function when a star rating is clicked:
function saveRating(){
if ($('.star.star-5')[0].checked){
alert("Rating 5 saved");
}
// Additional checks for other star ratings
}
Replacing the alerts with actual method calls like below doesn't seem to work as expected:
"MySqlJDBC.rate(servletPath, \"1\");"
"MySqlJDBC.rate(servletPath, \"2\");"
"MySqlJDBC.rate(servletPath, \"3\");"
"MySqlJDBC.rate(servletPath, \"4\");"
"MySqlJDBC.rate(servletPath, \"5\");"
While the alerts display correctly, calling the Java methods seems to fail, leaving me puzzled about why the alert works but not the method invocation.