views:

39

answers:

1

I'm doing one litle project with JSP for topic Library. I want to create a rating system for books in library when end-user view detail of book and rating for this book. Can anyone give hints or tutorials how to go about this?

+1  A: 

I'd suggest to use the jQuery Star Rating plugin for this. Check the demo page how it all look like. The JSP/HTML basically look like this (you only need to put the necessary JS/CSS/image files in the public webcontent). The magic is done by giving the radio buttons the class name star.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Star rating demo</title>
        <link rel="stylesheet" href="jquery.rating.css">
        <script src="jquery.js"></script>
        <script src="jquery.rating.js"></script>
    </head>
    <body>
        <input name="star1" type="radio" class="star">
        <input name="star1" type="radio" class="star">
        <input name="star1" type="radio" class="star">
        <input name="star1" type="radio" class="star">
        <input name="star1" type="radio" class="star">
    </body>
</html>

In the server side you just use HttpServletRequest#getParameterValues() to obtain multiple selections by given field name. To check the rating, just determine how many are been checked.

String[] star1 = request.getParameterValues("star1");
if (star1 != null) {
    int rating = star1.length;
    // ...
}
BalusC