Communication between 2 servlets

Hi,
I’ve a problem. Not sure if it’s a simple one.
I have a web app with servlets (say Servlet1, Servlet2, etc.) in it. I use a SQL query in Servlet1 and fetch an employee’s information (say empinfo) from the database. This is a string value. Now, I need to pass this “empinfo” to Servlet2.
I might sound dumb till here but please continue till the end to know what I still have to say…
1.     I tried using getters and setters. Servlet2 has the “empinfo” value I need. This is the first time Servlet2 is accessed.
2.     But, think that Servlet1 is transferring the control to an html page. And, this html page submits its parameters (say manager) to Servlet2. And, when this html passes its control to Servlet2, the “empinfo” value I need is gone because I used “empinfo” as a class member/global.
3.     So, when the control enters the Servlet2 the second time everything is lost and this is when I need the “empinfo” value.
4.     I cannot make the “empinfo” value in Servlet2 “static” because it keeps changing.
Note: I tried with all these: httpsession, reflection, etc. but nothing seems to fulfill my task.
If I could find a way to cache the Servlet1 object to use it in Servlet2 then I think my job is half done because even if I let Servlet2 keep a reference of the Servlet1, the html page is ruining the desired result.
Hope I’m clear and it is understandable.
Any help is appreciated.
Thanks in advance.

Depending on your need you could use one of these:
a) use ServletContext to store the emp data, so that all other webapp elements (servlets, jsp) could access thit information:
String empInfo = ...//get it from the db
ServletContext sc = getServletContext();
sc.setAttribute("com.myapp.empInfo", empInfo);
// you can either forward / include servlet2 here, or simply let the user click a link or sth, the value will still be accessible until some other web component removes it, or you shutdown the serverb) if the flow of control in your app is that servlet1 takes the info from the db, and then the user goes to servlet2, you could store the emp info in the request as an attribute, and use a RequestDispatcher:
String empInfo = ...//get it from the db
request.setAttribute("com.myapp.empInfo", empInfo);
RequestDispatcher rd = request.getRequestDispatcher("servlet2"); // maybe this could be a JSP if it is used to present the result to the user?
if (rd != null) {
    rd.forward(request, response);
} else {
/// probably should not happen, but do take care of this
}This would require you to prevent the user form being allowed to go to servlet2 directly, not through servlet1
c) httpsession should work fine, unless you have cookies disabled, and you don't use URL rewriting, but you gave us to little information to know what is wrong
Hope I could help a little, I'm still lerning this stuff myself.

Similar Messages

  • Communication between Applets & Servlets

    How do you communicate in between Applets & Servlets ?

    http://forum.java.sun.com/thread.jsp?forum=45&thread=525518&start=0&range=15#2519429

  • No communication between applet - servlet

    hi
    my applet and my servlet is not at all communicating in the browser.
              any body knows how to solve this problem?
              in my applet code:Jus i am pasing as name string to invoke the serlvet via URL
              String location = "http://ctp-vi0275:8880/HandlePassword?"+"Name=XXX";
              URL testServlet = new URL( location );
              URLConnection servletConnection = testServlet.openConnection();
              servletConnection.setDoInput(true);
              servletConnection.setDoOutput(true);
              servletConnection.setUseCaches (false);
              servletConnection.setDefaultUseCaches (false);
              servletConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
              servletConnection.connect();
              i have changed server.xml file to listen the port number 8880.(in tomcat)
              in my servlet code:
              doGet Method in servlet
              String str = req.getParameter("Name");          
              System.out.println(str);
              here i am jus printing the name
              but when i run my applet is not at all invoking the serlvet - HandlePassword.I have placed the
              servlet in ROOT\web-inf\classes\HandlePassword
              in web.xml
              <web-app>
              <servlet>
              <servlet-name>HandlePassword</servlet-name>
              <servlet-class>HandlePassword</servlet-class>
              </servlet>
              <servlet-mapping>
              <servlet-name>HandlePassword</servlet-name>
              <url-pattern>/HandlePassword</url-pattern>
              </servlet-mapping>
              </web-app>
              where i am doing wrong here?

    You do following things and let me know:
    1. Does the servlet work when you type "http://ctp-vi0275:8880/HandlePassword?Name=XXX" in your browser?
    2. Run applet using appletviewer. Does it work?
    3. If it works using appletviewer then enable java console in your browser and see error stacks if any.
    4. If there are applet security errors on java console, try creating servlet URL in applet code by calling getDocumentRoot() method and see what happens.

  • Communication between Managed servlet using ProxyServlet

              Hi,
              I have multiple Managed servers running on the same host, each hosting one web
              app on a particular port.
              The Admin server runs on port 7001.
              Example :
              The Managed Server hosting the Session Manager is running on 7100, and the
              Managed server hosting the DSLTools is running on port 7200.
              The following link works -
              http://localhost:7100/sessionmgr/servlet/sessionmgr
              Now when I click on DSLTools button on the page displayed by the above link,
              it takes me to
              http://localhost:7100/dsltools/servlet/dsltools
              whereas, I want it to take me to
              http://localhost:7200/dsltools/servlet/dsltools
              If I type the http://localhost:7200/dsltools/servlet/dsltools
              in the web browser, it works.
              So, ques is how can I go from Session Manager running on port 7100 to
              DSL Tools running on port 7200 ?
              I am trying Proxy by path using HttpProxyServlet, but it doesn't seem to work.
              I may be doing something wrong setting up HttpProxyServlet to handle this,
              but not sure what ? Any suggestions.
              I don't want to hard code the port numbers in the Session Manager servlet
              for obvious reasons.
              A quick response will be appreciated.
              Thank you very much
              -Anil Varma
              

    Hi jDee
    I�m not sure that the connection is kept opened, I mean by �you need to know that http connexion, DataInputStreamand DataOutputStream are always opened� that I don�t make an explicit call to close() method.
    My aim is to keep the http connection alive, because the Servlet needs to send with push mode some request to the Midlet. The Midlet handles the request and answers the Servlet.
    the behavior of my application is the following:
    DataInputStream dis=null;
    DataOutputStream dos=null;
    they are 3 modules: mobile client (J2ME), Mobile Server (J2ME), Coordinator (Servlet)
    1-Server: open Httpconnection with Servlet
    2-Server: open dis and dos
    3-Server: send user & passwd trougth dos
    4-Coordinator: check user&passwd
    5-Coordinator: send response
    6-Server:keep connection opened
    7-Server: execut while(dis.avalaible()<1) {};
    8-Client: send Request to coordinator
    9-Coordinator: redirect Request to the right Server
    10-Server: get request dis.read()
    11-Server: handles the request
    12-Server: answer the coordinator dos.write()
    13-Coordinator:redirect the Response to the right Client
    14-Client:get answer coming from Coordinator
    Regards
    -Med-

  • Communication between 2 servlets/java classes.

    Hi,
    I’ve a problem. Not sure if it’s a simple one.
    I have a web app with servlets (say Servlet1, Servlet2, etc.) in it. I use a SQL query in Servlet1 and fetch an employee’s information (say empinfo) from the database. This is a string value. Now, I need to pass this “empinfo” to Servlet2.
    I might sound dumb till here but please continue till the end to know what I still have to say…
    1.     I tried using getters and setters. Servlet2 has the “empinfo” value I need. This is the first time Servlet2 is accessed.
    2.     But, think that Servlet1 is transferring the control to an html page. And, this html page submits its parameters (say manager) to Servlet2. And, when this html passes its control to Servlet2, the “empinfo” value I need is gone because I used “empinfo” as a class member/global.
    3.     So, when the control enters the Servlet2 the second time everything is lost and this is when I need the “empinfo” value.
    4.     I cannot make the “empinfo” value in Servlet2 “static” because it keeps changing.
    Note: I tried with all these: httpsession, reflection, etc. but nothing seems to fulfill my task.
    Actually, Servlet2 lets the users to download the “empinfo” when a link on the html page (which sends the parameters to this servlet) is clicked.
    I used httpsession to store this “empinfo” in Servlet1 and used to grab the value in Servlet2.
    Then, I ran this app on my localhost. Then:
    Step1: I opened up one browser and when I clicked the link on html, I checked the “empinfo” value. It was fine.
    Step2: I opened up another browser and when clicked the link on html, I checked the “empinfo” value. It worked again.
    Step3: Now, I went back to the html page in the browser1 and clicked the link and checked to see the “empinfo” value and now it has the value of that in browser2.
    The “empinfo” always had the latest value. Previous values are overwritten.
    If I could find a way to cache the Servlet1 object to use it in Servlet2 then I think my job is half done because even if I let Servlet2 keep a reference of the Servlet1, the html page is ruining the desired result.
    If anyone can let me know how to do this with normal Java classes even that works for me.
    Thanks in advance.

    Thanks for the reply.
    Actually, when I used the session the IE browser behaved properly and its the FireFox that was weird.
    I think this is because Firefox uses single cookie for many instances of itself.
    Thanks again.

  • How to link between 2 servlets which are in 2 diferent servers

    I tried to move between 2 servlets which are residing in 2 different servers using the response.Redirect("myurl") method but when i try to return from the second servlet it gave me an error saying the response has been committed. I also tried using the request.getRequestDispatcher("myurl") method but this method does not seem to work as the servlets are in different servers. Anyone who have encountered this problem before please help. Thanks

    A RequestDispatcher only works within one JVM so cannot be used in your case. sendRedirect() causes the client to request the second servlet. To return to the first servlet, you need to sendRedirect() again. Basically, there is no link between the two servlets and you are communicating via the client (presumably a browser). You cannot pass session or servlet context attributes between the two servlets because they ruin in separate JVMs.
    If you're already using sendRedirect() in boht places and the second servlet is giving an error, then there's a problem with that servlet. Perhaps you could post the code and the error.
    If you want direct communication between the servlets, you need to custom build a link using HTTP, RMI or other protocols. There are many examples on this forum.

  • Communication between two Macs Server

    Communication between two Macs Server:
    Can they work together and communicate and interact normally in a PowerMac network, OS X 10.5.8 Server installed, and a MacPro computer that is running Server 4.0.3 on Yosemite? Had to do some additional implementation?
    Regards

    from the JavaDocs:
    http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html
    getContext
    public ServletContext getContext(java.lang.String uripath)
    Returns a ServletContext object that corresponds to a specified URL on the server.
    This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container.
    In a security conscious environment, the servlet container may return null for a given URL.
    Parameters:
    uripath - a String specifying the context path of another web application in the container.
    Returns:
    the ServletContext object that corresponds to the named URL, or null if either none exists or the container wishes to restrict this access.
    See Also:
    RequestDispatcher

  • Communication between SAP and 3rd Party Systems using IDOC HTTP XML Interfa

    Hi
    i am try do
    Communication between SAP and 3rd Party Systems using IDOC HTTP XML Interface
    With The help of SDN Contribution
    link----
    ( have look on it)
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/4943f2b7-0a01-0010-37af-faff35b2f08c
    I am getting error in
    Partner system as HTTPLOG and "Execute" to check the results
    Error is --  Port could not be created
    RFC destination HTTPLOG Not specified for system HTTPLOG
    any 1 have any idea  if plzzzzzzzz...........
    Thank u
    Ram

    Hello .
      we are also in  process of implementing the same
    could you share the knowledge pl?
    1)is it a separate add on with ALE to saphr
       or using ECC ??
    2)can u share the configuration part ??
    we are trying it on webas as addon 3.0 .

  • Applet communication with struts servlet

    Hi
    I�ve seen a lot of examples where a Java applet communicates with a servlet.
    I�ve made a web application using Struts, and i would like to know if it is possible to use an applet (View) and send to Stuts some data, I mean, call an action like http://localhost:8080/ViewRoads.do.
    Is it possible? ,Where can I find some examples about?, could anyone explain how would it work?, any good book to read about?.
    Thank you.

    I'm sorry but don't you have a communication source code example between a servlet and an applet that does work ? I'm looking for one of these since Two days already.
    thanks

  • Diagram with communications between all XI components

    Is there a diagram on help.sap.com or somewhere that along with specifying the communication connectivity between all of the XI components it also has the URLs and RFC destinations that correspond to the cache refreshes, etc.
    This would really help troubleshoot some intermittent problems I am having.  Much appreciated.

    Hi George Hamilton ,
    The following web-sites give u step-by-step solution for communications between all XI components :
    SAP XI Infrastructure : Demo Example configuration
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/605c8e2f-d611-2a10-5187-abd511fa339b
    SAP Security Guide XI
    http://help.sap.com/saphelp_nw04/helpdata/en/14/ef2940cbf2195de10000000a1550b0/frameset.htm
    XI Configuration guide
    http://help.sap.com/saphelp_nw04/helpdata/en/d7/f01a403233dd5fe10000000a155106/frameset.htm
    Technical Communication between configuration tools, Integration Builder tools and monitoring tools
    http://help.sap.com/saphelp_nw04/helpdata/en/5e/f85141196ff423e10000000a155106/content.htm
    Monitoring Set Up guide for SAP Netweaver 04
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/df1a6313-0a01-0010-c9a2-d76d3f115d42
    Process Integration : Demo Example configuration
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/80da7e60-d511-2a10-8885-f9ee5b36d63b
    Troubleshooting the File Adapter
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/troubleshootingtheFile+Adapter&
    Xi message processing monitoring & troubleshooting
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/2f2a9fa2-0a01-0010-32ac-d281db722b86
    SAP XI- New possibilities in SAP Integration
    http://www.english.bcc.com.pl/pad_files/aw_files/260_EN_AW_096_DB21_SAPXI_ENG.pdf
    Interoperability between Microsoft BizTalk Server 2004 and SAP XI 3.0
    http://download.microsoft.com/download/5/7/f/57f1490e-8a8d-497b-bbae-ec2a44b3799f/BizTalkSAPXIInterop.pdf
    Supportability Set up guide : SAP Netweaver 04
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cc1ec146-0a01-0010-90a9-b1df1d2f346f
    *******Pls reward points if u find this useful
    cheers!
    gyanaraj

  • Communication between c++ and java

    Hi all,
    I am developing a client-server system using C++ and Java.
    C++ programs is used for client part while Java program (servlet) is used in server side.
    I want to ask:
    How can I make communication between them?
    Thanks

    Servlets talk with a Web server and a Web Browser. Unless the C++ app is a Java Servlets client or server then you cannot communicate directly through HTTP and JSP with the C++ app.
    Look at RMI, and CORBA. CORBA is a non-Sun made protocol and RMI is a Sun-made protocol. For best results read the information about each method - RMI and CORBA (which go hand-in-hand).

  • Is in PI7.1 possible asynchronous communication between SOAP and ABAPProxy?

    Hi,
    when method execute_asynchronous has disapeared since XI/PI 7.1, is
    there still way how to use ABAP proxy in asynchronous way?
    We need to build asynchronous connection SOAP->PI->ABAP_Proxy.
    In PI, both interfaces are defined as asynchronous (outbound for SOAP and
    inbound for ABAP Proxy).
    Despite of this fact, when message is sent, it is processed
    synchronous way.
    I have set breakpoint in my implementation of method for ABAP Proxy
    message processing. When message is sent and breakpoint is reached,
    whole connection stays open (between SOAP and PI and between PI and
    ABAP Proxy) and waits for processing method (the breakpointed one) to
    return. Only when processing method returns, is connection finelly
    closed.
    If i understand it correctly, this is synchronous behavior. In
    asynchronous behavior, as i understand it, should be connection
    between PI and ABAP Proxy of application server closed immediately
    after message has been delivered. This mean before my processing
    method is even called.
    The same could be said about SOAP and PI communication. Connection
    should be closed immediately after PI has received message. From
    definition of asynchronous communication of PI is obvious, that PI
    should receive message correctly and close connection to sender system
    even when receiver is unreachable. It should deliver message later
    when, receiver system is back on line. So why it keeps connection to
    sender system open while it waits for receiver?
    Why is this happening, when both interfaces are defined as
    asynchronous? Could be the reason for this, if APPLICATION
    ACKNOWLEDGEMENT is set on by default? If so, how can i change it
    to SYSTEM ACKNOWLEDGEMENT, or disable it at all?
    Or is this kind of asynchronous communication even possible since
    XI/PI 7.1 ?
    Processing of message we are sending can take some time, so we dont
    want connection pending open while waiting for finish of
    processing. Thats the reason why we have chose asynchronous model to
    use.

    Quote from How to Use the J2EE SOAP Adapter:
    "If you select Best Effort, the Web service client will receive a response
    message in the SOAP body. Otherwise, the Web service client will not receive a
    response message if no error occurs."
    "if no error occurs" - that is the problem. In either case he still
    waits if some error occure or not. I dont want it. Once PI has
    received message, I want the connection with sender to be closed. If
    there will be error in communication between PI and reciever, I want
    to see it only in PI log. That mean no notification to sender to be
    send about that error.
    Is that possible?

  • Communication between Best Buy and Apple

    Where is the communication between these two companies? It's frustrating to have NO CLUE if a phone will come in a day or in 5 weeks. Who at Apple is deciding what they end to what stores? Obviously, Best Buy has to pay for the phones. There has to be some sort of communication. 
    Would it really be that hard for someone high up in Best Buy to communicate with Apple? Maybe a list from each store of their orders and what they are waiting on. Give that to Apple. Apple can give some sort of answer. Exepect this much in this time frame... expect this much later. I mean, something. Instead of leaving everyone in the dark, completely. 
    Someone at Best Buy corporate has to have SOME clue how Apple is shipping and to what stores. To say no one has no clue at all, is nuts. And if it's true... Best Buy needs to get a clue. DO SOME WORK FOR YOUR CUSTOMERS. At least get some truth, so if we need to go elsewhere, we can. It would be better for both sides.

    Apparently since they come on UPS, they don't know when the shipments are coming in or how much. Which I think is bull.
    If that's the case, what I want to know is HOW do they know they received the amount they were expecting? If they don't know how much they're getting or when they're getting a shipment, then what's stopping the delivery man from stealing a box, and they wouldn't know any better? Maybe the higher up manager's know, and they aren't allowed to reveal that info, but there has to be a checks system in there somewhere verifying the stock received.

  • Communication between iViews

    How to realize communication between two iViews of the same window but not the same portal page? I tried with using firing portal events but this doesn’t seem to work with Mozilla Firefox. Do you have any other ideas?
    The sending iView is a portal application the receiving iView a Web Dynpro for ABAP application (so I cant use JavaScript, I guess).
    Thanks!
    René
    Edited by: Rene Guenther on Jan 10, 2008 3:29 PM

    Hi Mrkvicka,
    To enable communication between iviews you need to use the EPCF .
    You can raise an event in the component of the first iview and define an OnClick event.
    this event you can subscribe from the other iview
    Refer to this link to get a more clear picture
    DropDown Selection and EPCF
    also refer to
    EPCF
    hope this helps,
    Regards,
    Uma.

  • Communication between jsp and abstractportalcomponent

    Hello All
    Communication between jsp and abstractPortalComponent.
    jsp contains one input text field and one submit button.
    when the user clicks on submit button it will call the component and that input value will
    display in same jsp page.
    how this communication will happen?
    Rgrds
    Sri

    Hi Srikanth,
    In the JAVA File, 
    OnSubmit Event,
    String inputvalue ;
    InputField myInputField = (InputField) getComponentByName("Input_Field_ID");
    if (myInputField != null) {
                   inputvalue = myInputField.getValueAsDataType().toString();
    request.putValue("textvalue", inputvalue);
    request is IPORTALCOMPONENTREQUEST Object.
    In JSP File,   to retreive the value,
    <%
    String  textstring = (String) ComponentRequest.getValue("textvalue");
    %>
    In PORTALAPP.XML File,
    <component name="component name">
          <component-config>
            <property name="ClassName" value="classname"/>
            <property name="SafetyLevel" value="no_safety"/>
          </component-config>
          <component-profile>
            <property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>
          </component-profile>
        </component>
    Using the code above, You can pass and read values between abstract portal component and Jsp Page.
    Instead of this, I suggest you to use JSPDYNPAGE Component for Data Exchange.
    Check the [Link|http://help.sap.com/saphelp_nw2004s/helpdata/de/ce/e0a341354ca309e10000000a155106/frameset.htm].
    Hope this helps you.
    Regards,
    Eben Joyson

Maybe you are looking for

  • Cannot forward one page PDF files from mail app

    My earlier topic had incorrect problem report so I've created a new topic. The problem is i cannot forward one page PDF file from mail apps. I use imap set up for my work email. Multi page PDFs, photos, docs, numbers, all forward OK for both windows

  • J_security_check 404 error Please please help me

    I am new to this forum although I have been lurking around for while:) I have a question about j_security_check. I am working in Apache Tomcat server and I want to set up form based authentication. So I used j_security_check and I get an error 404 j_

  • Online gaming issue with WRT54G2V1.

    Hi I have a WRT54G2V1 (firmware 1.1.01) router hard wired to 4 computers in the house.  I have a Siemens Speedstream 4200 Series Modem. I play Mechwarrior IV and I have some connection problems.   The MW4 sites say to do the following: Make a static

  • Best project & export settings for GoPro 1080p 30fps - YouTube

    Hi all, Just made a new video for YouTube and it's come out a little grainy, no where near as good as the original. I know YouTube compresses footage but looking at other users with the same equipment my video quality is sub par, I seem to be editing

  • How do I Change account settings for LINE to enable login

    HOw do I find account settings to allow for login to app LINK. Cant't find this anywhere. Feeling small.