如何从<a href=""> tag in JSP

时间:2015-08-01 14:53:39

标签: jsp servlets hyperlink http-post

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?

1 个答案:

答案 0 :(得分:1)

您可以使用表单提交而不是锚点。这应该让你开始 - W3 schools - form tag。例如:

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

但是,您无法在按钮内部使用span标记,因此您可能必须使用javascript来提交表单而不是按钮(将单击功能附加到提交表单的glyphicon)。

相关问题