| Author |
Linking to servlets using href
|
Subil Abraham
Greenhorn
Joined: May 21, 2003
Posts: 4
|
|
I have a JSP page which contains 3 links shown below <a href=".../MyServlet">Function1</a> <a href=".../MyServlet">Function2</a> <a href=".../MyServlet">Function3</a> and they reference the same Servlet(viz MyServlet). I was wondering if the Servlet(MyServlet) is capable of identifying which link is clicked. I know it possible using forms but i wanted to know if i could associate a unique action for each link. Any kind of help would be appreciated.
|
 |
Leandro Oliveira
Ranch Hand
Joined: Nov 07, 2002
Posts: 298
|
|
Try this: <a href=".../MyServlet?action=function1">Function1</a> <a href=".../MyServlet?action=function2">Function2</a> <a href=".../MyServlet?action=function3">Function3</a> and at your servlet 'MyServlet.java' try this: public class MyServlet extends HttpServlet(){ public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletExcetption,IOException{ response.setContentType("text/html"); PrintWriter out=response.getWriter(); String function=request.getParameter("action"); //this is that parameter we passed within the link if(function.equals("function1")){ //code for function 1 }else if(function.equals("function2")){ //code for function 2 }else if(function.equals("function3")){ //code for funtction 3 } } }
|
 |
 |
|
|
subject: Linking to servlets using href
|
|
|