1

I would like to call doPost() method of a servlet from <a href>, but it calls doGet() method. How can I call to doPost() method?

This is my code.

<ul class="nav navbar-nav navbar-right">

    <li><a href="newAdmin" ><span class="glyphicon glyphicon-user"></span> New Admin</a></li>

    <li><a href="index.jsp"><span class="glyphicon glyphicon-log-out"></span> LogOut</a></li>

  </ul>

newAdmin is the url pattern of my servlet and I would like to call doPost() of that servlet. How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • use javascript, ajax call – SatyaTNV Aug 01 '15 at 14:59
  • 1
    If you want to invoke HTTP `POST` from the link, you need to use JavaScript for `POST`ing the form. The answers to [How to call doPost() servlet from a hyperlink in jsp](http://stackoverflow.com/questions/11287642/how-to-call-dopost-servlet-from-a-hyperlink-in-jsp) should help you forward. – Mick Mnemonic Aug 01 '15 at 15:01

1 Answers1

1

You could use a form submission instead of an anchor. This should get you started - W3 schools - form tag. For example:

<ul class="nav navbar-nav navbar-right">

<li><a href="newAdmin" ><span class="glyphicon glyphicon-user"></span> New Admin</a></li>

<li><form method="POST" action="index.jsp"><button type="submit"> LogOut</button></form></li>

However you can't have a span tag inside a button so you might have to use javascript to submit the form instead of a button (attach a click function to your glyphicon that submits the form).

user1886323
  • 1,179
  • 7
  • 15