Regarding using a JSP as i said i think its the best and fastest way to do respond to your AJAX requests if you have little thing calls, however if your application uses AJAX extensively it would be better if you implement a dedicated Servlet to respond to AJAX requests, the servlet will act as a front controller, and you will differentiate between AJAX calls using a parameter for example "operation", and passing additional parameters if needed
so for example if you for example if you want to check if the user already exists you would call
http://yourpath/yourapp/ajaxcontroller?operation=checkUserExists&username=foo
and if you want for example make another AJAX call to get user information you would use the same path but change the operation value
http://yourpath/yourapp/ajaxcontroller?operation=loadUserInfo&userId=10
from the server side you will have a servlet that reads the operation parameter from the request and then gets the correct handler for that operation by sending the operation
string to a factory object for example, which will give you back the handler, then you can invoke a certain method that object to get the response string to be sent back to the user. to support what i am advicing here is an abstract view
first you need an interface that has a method named geteAjaxResponse(HttpServletRequest request) you can pass other parameters if needed.
then in your AjaxFrontController you can define a servlet with the following logic
and finally for each AJAX operation you will have a class that extends IAjaxProcessor and define the getAjaxResponse() method.
i ommitted the code needed to create the factory since its obvious, in addition using some naming conventions a lot of code could be reduced, and you could use a configuration file to specify the names and classes used for AJAX so that you will not have to recompile your code if you will have to add a new AJAX operation.
(peace)