Reputation: 221
My question is that :- In interview interviewer asked me: In servlet there is a method which has 10 params. and the request is send to other controller or servlet. in other servlet we need only 6 params. what we have to do?
I answered: you can get params with the help of req.getParameters(1,2,3,4,5,..);
OR
for each element i can write req.getParameter(1);req.getParameter(2);...... (6);
OR
we can set all required values in session scope
but the interviewer was not satisfied with my answer...
Please tell me what is the best answer for the same.
Thanks in Advance :)
Upvotes: 1
Views: 122
Reputation: 5090
It sounds like the interviewer wanted to hear you talk about the adapter pattern, and not what specific code you were going to write.
From your comment, it sounds like you have not heard of patterns before. They are common designs or approaches to a particular problem, and they make it easier to 1) spot a particular problem which has a common solution and 2) to describe to other developers the design or approach.
The adapter pattern translates one interface (the method with 10 parameters) into a different interface (another method with 6 parameters)
In this case, the code solution might involve req.getParameter but the interviewer wanted to see that you could identify this situation as one where you would use the adapter pattern.
Upvotes: 1