Link to home
Start Free TrialLog in
Avatar of vincehon
vincehon

asked on

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



Avatar of dualsoul
dualsoul

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
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).
Avatar of vincehon

ASKER

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)

ASKER CERTIFIED SOLUTION
Avatar of dualsoul
dualsoul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial