Solved

jsp called multiple servlet and remain in the same page

Posted on 2003-11-09
4
610 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now