当用户点击链接时,如何从jsp到servlet获取url值? [英] How to get the url value from jsp to servlet when a link is hit by the user?

查看:86
本文介绍了当用户点击链接时,如何从jsp到servlet获取url值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jsp中有以下代码

I have the following code in my jsp

<table>
    <c:forEach var="link" items="${weblinks}">
        <c:if test="${link.featured}">
            <tr>
                <td>
                    <span>${link.title} (Hits : ${link.numOfHits})
                        </span>

                    <span>
                        <a href="<c:url value='${link.url}'/>">${link.url}  </a></span><br></td>
            </tr>
        </c:if>
    </c:forEach>
</table>

现在,我希望当任何用户单击链接时,链接会打开,并且链接的URL也将转到servlet.我已经实现了第一个功能,但是如何在servlet中获取url,以便可以更新数据库中的网站链接已被删除的点击数?

Now i want that when any user click on the link the link opens and the url of link also goes to the servlet. I hava achieved the first functionality but how i'll get the url in servlet so that i can update the number of hits, a website link has recevied, in database?

请帮助我.我有谷歌它,但没有得到答案.如果使用了javascript,请也向我解释Java脚本代码?

Please help me. I have google it but don't get the answer. If javascript is used then please explain me java script code also?

推荐答案

更新

<a href="<c:url value='${link.url}'>
<c:param name="hits" value="${link.numOfHits}"/></c:url>">${link.url}  </a>

这将添加一个查询字符串,该字符串的参数为命中数,其值为命中数

this will add a query string which has parameter number of hits which has the value of number of hits

在具有request.getParameter("hits")的servlet上,您将获得servlet的点击次数

On the servlet with request.getParameter("hits") you will get the number of hits on the servlet

引用 http://www.roseindia.net/jsp/simple -jsp-example/JSTLConstructingURLs.shtml

希望这会有所帮助

这篇关于当用户点击链接时,如何从jsp到servlet获取url值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆