design - Designing a generic servlet which handles request dispatching -


I have a design question :)

I have more than one servlet but I do not configure Each time a fan wants to expand a new servlet and HTTPSvlevate with a new name. I was thinking of a generic servlet which transmits different parameters to different sections which are actually handling the request.

Ex: Both of those calls will be handled by the same generic servlet, but different services (classes).

/ serviceservlet? Action = action1 and param1 = test1 and param2 = test2 / serviceservlet? Action = action 2 and param21 = test

This can be done in many different ways and I do not know which design to go by. I have just been using Guise for bootstrapping and this Looks like this:

@Sington extends the public class service server HotSpervatelet {

  private static final string PARAM_ACTION = "action"; Private Final Service 1 Service 1; // Service 1 is an interface Private Final Service 2 Service 2; // Service2 is another interface @ Public Service Service (Final Service 1 Service 1) {this.service1 = service1; } @ Public Service Service (Last Service 2 Service 2) {this.service2 = service2; } @ Override Public Wide Dood (Last HTTPSvette Request Request, Last HTPreserve Response)) {String Action = Servlet Utility String Parameter (Request, ParamA_Action); If ("Action 1". Axles (action)) ... ... to verify that the correct type of parameters are correct before typing below. Process (request.getParameter ("param1"), request.getParameter ("param2")); } Else if ("action2" .equals (verb)) ... ... to verify that to correct the parameters, type it correctly before typing. Process (request.getParameter ("param21")); In theory, I would like to handle services in a more general way and I want to later as easy as adding new services. , But I do not want to loose the type of type. What do you think is the best strategy? 

/ B Johns

Web programmers do not write this type of code themselves anymore They use web frameworks like Straps or JSF or Spring (if you are a Java programmer), which provide elegant implementation of the requests to apply requests to mapping requests for the mapping of the sections. More, very much.

However, if you really want to "do your roll" , then I can suggest it before that if you do not use a statement, your servlet Inside you should use a map (i.e., Hashmap), which maps the request URI to service classes. On the servlet, the map service should be filled with sections examples. Add a method inside your servlet, getServiceClass () which returns UTI and ACTIONS to HttpServiceRequest and looks for your service class. Better yet, you should map service segments, do not request parameters, but for URI: myapp / serviceX maps should be done in ServiceX.class. Define a service interface, service, with an executable method and call the method executed with servlet.

To summarize: 1) Load the map of the requested URI service class when the service is in the service.) 2) A service interface between the servlet and the service class Define the .3) From servlet, hold the URI (relevant portion of the URI) with the request and call it the service and its executed method (or the name you want to choose).


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -