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