如何将HTML页面中的链接值传递给其他Web服务

时间:2022-08-26 23:19:05

If I have a HTML or a JSP page having list of sports like below.

如果我有一个HTML或JSP页面,其中包含如下所示的体育列表。

Tennis
Football
Hockey
Cricket

网球足球曲棍球板球

All these 4 should be a Link. If I click on any of them it should return some details wherever clicked. For this I need to pass this sport name to a REST client which will pass this as a parameter to a rest service.

所有这4个应该是一个链接。如果我点击它们中的任何一个,它应该返回点击的任何细节。为此,我需要将此运动名称传递给REST客户端,该客户端将此作为参数传递给休息服务。

My question is how to pass the value of a link whichever clicked from HTML page to a Java application like we pass text box or check box values from HTML using the form action? Or is there any better approach, please suggest

我的问题是如何将从HTML页面点击的链接的值传递给Java应用程序,就像我们使用表单操作从HTML传递文本框或复选框值一样?或者有更好的方法,请建议

2 个解决方案

#1


1  

I suggest you to look at jQuery.ajax. Basically you'll want to create an XHR (GET, POST etc depending on the rest client configuration) and send your data.

我建议你看一下jQuery.ajax。基本上你会想要创建一个XHR(GET,POST等,具体取决于其他客户端配置)并发送您的数据。

Here is a very crude example on the subject;

这是一个关于这个主题的非常粗略的例子;

$('.sports').on('click', function() {
   var clickedElementText = $(this).text();
   $.ajax({
     url: "/your/endpoint/url",
     method: "POST",
     data: { 
        sportName : clickedElementText;
     },
   }).success(function( response ) {
     /* success callback */
   }).failure(function( jqXHR, textStatus ) {
     /* failure callback */
   });
}

#2


1  

Ajax is a good way or you can just define the element

Ajax是一种很好的方法,或者你可以定义元素

<a href="/sports/detail?sportName=tennis">

#1


1  

I suggest you to look at jQuery.ajax. Basically you'll want to create an XHR (GET, POST etc depending on the rest client configuration) and send your data.

我建议你看一下jQuery.ajax。基本上你会想要创建一个XHR(GET,POST等,具体取决于其他客户端配置)并发送您的数据。

Here is a very crude example on the subject;

这是一个关于这个主题的非常粗略的例子;

$('.sports').on('click', function() {
   var clickedElementText = $(this).text();
   $.ajax({
     url: "/your/endpoint/url",
     method: "POST",
     data: { 
        sportName : clickedElementText;
     },
   }).success(function( response ) {
     /* success callback */
   }).failure(function( jqXHR, textStatus ) {
     /* failure callback */
   });
}

#2


1  

Ajax is a good way or you can just define the element

Ajax是一种很好的方法,或者你可以定义元素

<a href="/sports/detail?sportName=tennis">