• Post Reply Bookmark Topic Watch Topic
  • New Topic

Forwarding request attributes from jsp to servlet and then to subsequent servlet

 
yuv Smith
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am building an application that has two types of users.
While some of the fields (ie: username, email address, password) are the same for both user types, other fields are different for each user type.
Therefore, I would like to split up the process of registering (ie: writing the user info to database) into two parts:
1) registering the common fields among both user types (servlet 1)
2) registering the specific fields based on the user type that is registering (servlet 2a and servlet 2b).

Therefore, once servlet 1 is processed, I wish to forward the request to servlet 2a or 2b depending on what type of user is registering.
I wish to do this since I will have other parts of my application that will make use of servlets 2a and 2b as well.

Is this possible to do (redirect request parameters from jsp to servlet and then to another servlet)? Any other suggestions?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That seems a strange way of doing things. Why not write a single servlet that uses several classes that contain the actual logic?
 
yuv Smith
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I indeed use a lot of helper classes but the bulk of the servlets is the retrieval of the attributes (and some conditional statements).
There will just be redundancy and I'm trying to minimize it.
If I have a separate servlet for each then I will have the following servlets:
servlet 1a - shared fields + usertype_a specific fields
servlet 1b - shared fields + usertype_b specific fields
servlet a - usertype_a specific fields
servlet b - usertype_b specific fields

As opposed to what I would like:
servlet 1 - shared fields
servlet 2a - usertype_a specific fields
servlet 2b - usertype_b specific fields
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would still be a very unusual design (not to mention that it introduces practical complexities for no gain, IMO). What if the situation changes and there are now 5 user groups? Would you want to introduce 3 more servlets? (That is a rhetorical question, the answer should be no.)

What redundancies would be introduced by having fewer servlets? It seems rather a way of simplifying the code, not to mention the flow of control. I would envision: 1 servlet, 1 base class for common fields, and 2 classes extending the base class for each user group.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!