How to link different Servlet together?

Posted by Harry Pham on Stack Overflow See other posts from Stack Overflow or by Harry Pham
Published on 2010-04-16T19:46:44Z Indexed on 2010/04/16 19:53 UTC
Read the original article Hit count: 248

First of all, I did not use Spring MVC. :) :) Just want to get it out first. Now what I have is different JSP pages that making calls to different Servlets. All the pieces work great individually but I kind of need to link them together. If all of jsp pages make GET request then it would be easy, since I would just pass a type via the web address, and on my servlet side, I would just enumerated through all the parameter, determine which type is it, and delegate to the right servlet. But not all jsp pages make GET request, some make POST request via form. Let see example

 A.jsp
 $.getJSON('GenericServlet?type=A', ...

 GenericServlet.java
 String type = request.getParameter("type");    
 if(type.equals("A")){
     //Somehow delegate to Servlet A (Not sure how to do that yet :))
 }

but in B.jsp I would have something like this

 B.jsp
 <form action="GenericServlet" method="post">
    <table border=0 cellspacing=10 cellpadding=0>
        <tr>
            <td>User Name:</td>
            <td><input type="text" name="username" size=22/></td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type="password" name="password" size=22/></td>
        </tr>
    </table>
    <input type="submit" value="Create User" />
</form>

It kind of hard for me to determine in GenericServlet.java that this need to go to servletB

© Stack Overflow or respective owner

Related posts about servlets

Related posts about servlet-dispatching