wood burning stoves 2.0*
The moose likes Servlets and the fly likes 2 servlet  in same screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "2 servlet  in same screen" Watch "2 servlet  in same screen" New topic
Author

2 servlet in same screen

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,
can i have 2 servlets in a single page?I am having a screen in servlet which displays the details of the caller to the agent.I need to display in the same page about another caller if anyone is in queue by fetching the customer waiting database.How can i do this?any idea about this ?I thought to do it in html frames.one frame which displays the details screen and the other frame should display that a caller is waiting in queue by using servlet which checks the database for every five seconds whether anyone is in queue and displays the message to the agent.Is this method correct.If not how
can i do this?

Thanks
[ May 09, 2008: Message edited by: preethi Ayyappan ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Frames would be one way to do this.
You might also want to look into RequestDispatcher.include.

If you really want to delve into best practices, you should think about moving all of the heavy lifting out of your servlets and into beans or plain old Java objects. Look up the "model, view, controller" pattern or 'MVC' for more on this. Once you've done this, it would be easy to mix and match the results from several different components into your pages.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
thanks.now i have done this in frame like i am having a html file which is having 2 frames.one is forward.jsp and another is custwait.jsp.In forward.jsp i am calling one servlet which is displayed in topframe consisting of pause and logout buttons.In custwait.jsp i am calling another servlet which just checking the database for every 5 seconds and displays some message at the bottom.If i click the logout button which is in the top frame,it is redirected to login page.but the bottom frame displays the following error:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.NullPointerException
com.example.servlets.Callwait.doGet(Callwait.java:35)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:686)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:656)
org.apache.jsp.custwait_jsp._jspService(custwait_jsp.java:51)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

OK, you have some basic debugging to do.
Have you looked at the generated servlet code to see what variable is on line 51 that could be null at the point when it is trying to be used?

You can find the generated code in the tomcat/work directory.



Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Preethi,

I have a question here? How are you making the call to the corresponding servlet from custWait.jsp for every 5 minutes..??

I know AJAX is one way to do it. But just curious to know how you have done it.

A piece of code would be helpful for better understanding.
[ May 17, 2008: Message edited by: Prasad Tamirisa ]

Regards,
Durga Prasad
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,

How are you making the call to the corresponding servlet from custWait.jsp for every 5 minutes..?

I am not refreshing the jsp page.in custwait.jsp,I am just forwarding to callwait.java which is a servlet and there only i am refreshing for every 5 minutes.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 servlet in same screen