0

Is it possible to link a servlet within a list within a .jsp file ?

<form>
<ul id="nav">
    <li class="current"><a href="HomeClientServlet">Home</a></li>
    <li><a href="TransactionsServlet">Transactions</a></li>
    <li><a href="StartTransferServlet">Transfer</a></li>
</ul>
</form>

The upper code wont work and im not sure how to do this.

*NOTE - The servlet needs to run doPost and not doGet.

As Jigar Joshi said I have tried to do this:

It didnt work and then i tried doing this instead:

    <form>
    <ul id="nav">
        <li class="current"><a href="<%=request.getContextPath()%>/HomeClientServlet">Home</a></li>
        <li><a href="<%=request.getContextPath()%>/TransactionsServlet">Transactions</a></li>
        <li><a href="<%=request.getContextPath()%>/StartTransferServlet">Transfer</a></li>
    </ul>
</form>

This one is invalid

<form>
<ul id="nav">
    <li class="current"><form action="<%=request.getContextPath()%>/HomeClientServlet" method="POST"><input type="submit">Home</form></li>
</ul></form>
Anonymous
  • 1,303
  • 4
  • 19
  • 31
  • take a look at this http://stackoverflow.com/questions/2349633/servlets-doget-and-dopost and you'll have a better idea of what you need to do – ikumen Jun 18 '13 at 04:30

2 Answers2

1

clicking on valid anchor by default makes a GET request, if you want to make a POST instead then either write javascript to handle on click and make POST or place a tiny form instead of anchor

replace anchor tag with something like below

<form action="<%=request.getContextPath()%>/TransactionsServlet" method="POST">
  <input type="SUBMIT">
</form>
jmj
  • 237,923
  • 42
  • 401
  • 438
  • Can you explain me how to change or make POST ? Like in code cause im not sure I understand what you meant – Anonymous Jun 17 '13 at 21:51
  • Its invalid to put form inside li tag – Anonymous Jun 17 '13 at 21:59
  • remove li then or [write javascript to make post](http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit) – jmj Jun 17 '13 at 22:00
  • If I remove li tag then this thread is obsolete cause the whole point was to make the
  • link to servlet doPost. I could remove the li tag but then I stand without a nav bar. And javascript is not my stongest language. But thanks for the try
  • – Anonymous Jun 17 '13 at 22:03