I have a requirement from a user to have a web page where they can perform CRUD operations on a list of users stored in a DB.
It will be hosted on Tomcat.
I threw a quick Servlet together that takes 5 parameters from the request and creates a userName in the DB with this data. Now I want to allow the user the ability to enter a username and click a button and if this username exists in the db then it will be returned and the page populated to allow the user perform some edits on the data.
My question is, should I just create a new Servlet for this data lookup service or somehow shoe horn the required functionality into the existing servlet that creates usernames in the DB
I have a requirement from a user to have a web page where they
Share
I don’t think it’s unreasonable to put this functionality in the same servlet. You’re operating on the same resources (db) and the functionality is inter-related, so putting it in the same functional component makes sense.
I’d start to pull functionality into a different servlet when you’re doing something fundamentally different e.g. operating on different databases, or there’s some requirement to deploy that functionality separately (e.g. booking sales vs. browsing information), or you need to apply servlet filters differently for different components.
To answer your question below, you need to somehow distinguish between the different operations. Options include:
The first example could be trivially handled by providing different servlets mapped on different paths. However I think the overhead of providing those servlet and mappings outweighs the ease of simple checking the request path.