如何在JSP中创建评级系统?(How to create rating system in JSP?)

编程入门 行业动态 更新时间:2024-10-26 16:30:37
如何在JSP中创建评级系统?(How to create rating system in JSP?)

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

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?

最满意答案

我建议使用jQuery Star Rating插件 。 检查演示页面的样子。 JSP / HTML基本上看起来像这样(你只需要在公共webcontent中放入必要的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>
 

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

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

通过上面的例子,它将返回1,2,3,4或5。

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>
        <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.

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

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

更多推荐

本文发布于:2023-08-01 01:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1351445.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   系统   JSP   system   create

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!