java 如何在 JSP 中创建评分系统?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3641577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 02:47:42  来源:igfitidea点击:

How to create rating system in JSP?

javahtmljsprating-system

提问by Kency

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?

我正在用 JSP 为主题库做一个小项目。当最终用户查看这本书的详细信息和评分时,我想为图书馆中的书籍创建一个评分系统。任何人都可以提供提示或教程如何解决这个问题吗?

采纳答案by BalusC

I'd suggest to use the jQuery Star Rating pluginfor this. Check the demo pagehow 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.

我建议为此使用jQuery Star Rating 插件。检查演示页面它的样子。JSP/HTML 基本上是这样的(你只需要把必要的 JS/CSS/图像文件放在公共网页内容中)。魔法是通过给单选按钮类名来完成的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>
        <form>
            <input type="radio" name="rating" value="1" class="star">
            <input type="radio" name="rating" value="2" class="star">
            <input type="radio" name="rating" value="3" class="star">
            <input type="radio" name="rating" value="4" class="star">
            <input type="radio" name="rating" value="5" class="star">
        </form>
    </body>
</html>

In the server side you just use HttpServletRequest#getParameter()to obtain the rating value.

在服务器端,您只是HttpServletRequest#getParameter()用来获取评级值。

String rating = request.getParameter("rating");
// ...

With the above example, it'll return 1, 2, 3, 4 or 5.

在上面的例子中,它会返回 1、2、3、4 或 5。