Solved

jsp called multiple servlet and remain in the same page

Posted on 2003-11-09
4
616 Views
Last Modified: 2013-11-24
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



0
Comment
Question by:vincehon
  • 2
4 Comments
 
LVL 15

Expert Comment

by:dualsoul
ID: 9712889
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
 
LVL 15

Expert Comment

by:jimmack
ID: 9712899
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
 

Author Comment

by:vincehon
ID: 9719497
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
 
LVL 15

Accepted Solution

by:
dualsoul earned 200 total points
ID: 9720184
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question