jsp called multiple servlet and remain in the same page

Dear Expert,

I have 2 components, one is JSP (test.jsp), the other is Servlet.

The JSP act like the User Interface to accept 3 parameters from the user.

The servlet will perform calculation based on a SINGLE parameter sent from the JSP.

After the user input 3 parameters,
1. How to call the Servlet 3 times in the same time (since the serlvet only calcuate one parameter)?
2. Let the user remain in the test.jsp while the servlet perform the calculation ?
3. How jsp can get the calculation result from the servlet ?

Thanks
Vince



vincehonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dualsoulCommented:
hm...why do you want to call your servlet 3 times?

i think it's more suitable to get all parameters from user -> call servlet, which will calcalate result -> reirect to result .jsp page, providing result info as JavaBean
0
jimmackCommented:
I don't know why your JSP contains three input fields when you are only going to process one in the servlet.  Why can't you do all three in one go?  How does the servlet know which one you want to process (are they in three different forms)?

When you press your submit button, the servlet will be called to process the results.  When it has finished, it should redirect back to the JSP including any calculation results as parameters.  In the JSP, you should check to see if any result parameters are present and if so, display them.

When the JSP is first called (presumably from a link), the URL won't contain any result parameters, so none should be displayed.

If this is simply a case of performing a calculation based on the user input (ie. if it doesn't require server-side data), why not just do this with JavaScript?  That way, the page won't change at all (apart from displaying the results of the calculation).
0
vincehonAuthor Commented:
Thx for all reply, I just want to simplier the situation.
Here is my web application:

I would like to set up a web site that allow user to sent SMS.

For the front end
test.jsp
- ask the user to input parameter, like the sender phone no., receive phone no, the SMS message....

For the back end.
1. It has a RouterServlet
- to accept the parameters and find the best route.
- based on the best route, relay the SMS request to other component,
known as ESMEServlet (also a Servlet)

2. ESMEServlet
- the ESMEServlet will then sent the SMS to the SMS service center.

If I split the multiple phone on RouterServlet, let say, there are 3 phone numbers. RouterServlet will call ESMEServlet 3 times.

-------------------------------------------------------------------------
As you can see, there are 3 tiers.
test.jsp --> RouterServlet --> ESMEServlet

The difficulty is that I need to get the return flag on each tier.
For the test.jsp --> RouterServlet
I need to know whether RouterServlet can successfully accept the SMS request from test.jsp

Once I get the return flag from RouterServlet, I will used this to inform the user whether his/her SMS sending is successfully or not.
If success, I will debit his bonus point.

For the 2nd tier
RouterServlet --> ESMEServlet.
Same as test.jsp --> RouterServlet. RouterServlet will also need to get the return flag from ESMEServlet to indicate whether ESMEServlet is invoked successfully or not

My question is:
1.How can I get the return from RouterServlet and inform this to the user on the test.jsp page?

2. for the test.jsp --> RouterServlet.
Assume RouterServlet can return the flag after it is executed 50%. Is it possible to return the flag from RouterServlet to test.jsp and then let the RouterServlet to execute the remaining part (in this case, RouterServlet will invoke ESMEServlet) ? I want to do this because I do not want the user to wait for a relative long period of time.

3. Is it possible for 2 different Servlets to cooperate in thread ? i.e. one continue to execute until the other has completed certain task. (like RouterServlet and ESMEServlet in my case)

0
dualsoulCommented:
1. i can't understand why you want to return something from RouterServlet. Just redirect from RouterServlet to result page (test_result.jsp for instance of even back to test.jsp, if you so like it), to pass some data from servlet (return flag fot instance) pack you data to JavaBean and pass it to .jsp.

2.  so, you can certanly call RouterServlet, and after it's finihed, call EMSServlet, what's trouble? Just don't call EMSServlet from RouterServlet. Call it standalone.
But in my opinion you should think/read about MVC paradigm, you have very strange design.

3. why?!
Think about design, may be you shouldn't use servlets to execute your tasks, may be to code special classes for it?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.