-4
 <button><span>ButtonName</span></button>

I need to fire a request to a Servlet after clicking a button, like ButtonName here. For some restriction I am unable to wrap it to a form submission or any other tag.

How can I do this ?

Shafin Mahmud
  • 3,831
  • 1
  • 23
  • 35
  • 1
    Java servlet? What about BUTTON-TEXT – Flocke Mar 26 '18 at 12:38
  • 1
    Welcome to Stack Overflow. When you created your account here, it was suggested you take the [tour] and read the [help] pages in order to familiarize yourself with the site. Please do so, especially [ask], before posting your next question here. – Ken White Mar 26 '18 at 12:39
  • this process does not support many inline css content such as hover. I designed a button with much effort. But just due to lack of knowing process I can not call my desired servlet from the button @Flocke – Abdur Razzak Rana Mar 26 '18 at 12:54

1 Answers1

1

You could wrap the <button></button> tag inside a <a></a> tag and mention href for the redirect url.

<a href="/someurl"><button>ButtonName</button></a>

But if you insist to use only <button> tag then you might find, there is no kind of attribute to tell a redirect url. You can see the available HTML button tag attributes. Yes of course you could have do it using a form submit. But you are not using that.

But yes, there is one way left. You could use the HTML onclick event attribute.

<button onclick="window.location='some/redirect/url'">Click me</button>

You might have noticed onclick attribute takes and run javascript and get executed on the element click event. So there is plenty more options if you want to exploit javascript for this.

Shafin Mahmud
  • 3,831
  • 1
  • 23
  • 35