Threadsafe servlet?

Hi,
Im developing a sevlet accesing an enterprise system using HTTP. I am using the Apache HttpClient package and have a questing regarding thread safety. The classes are like below:
EnterpriseClient.java:
public class EnterpriseClient
private HttpClient client;
MultiThreadedHttpConnectionManager connectionManager = null;
     public void create()
          // create a thread safe HttpClient.
          connectionManager =     new MultiThreadedHttpConnectionManager();
          client = new HttpClient(connectionManager);
     public String getEnterpriseData(String msisdn)
PostMethod post = new PostMethod("....");
String result = post.getResponseBodyAsString();
return result;
     public String setEnterpriseData(String msisdn, Strign data)
PostMethod post = new PostMethod("....");
post.setMessageBody(data);
String result = post.getResponseBodyAsString();
return result;
EnterpriseServlet.java:
public class EnterpriseServlet extends HttpServlet {
     EnterpriseClient myClient = null;
     public void init() throws ServletException
          myClient = new EnterpriseClient ();
          myClient .create();
     public void doPost(...) {
          // get enterprise data
          String reply = myClient.getEnterpriseData(id);
// analyze data
// set enterprise data
String reply = myClient.setEnterpriseData(id, data);
Would this code qualify as thread safe? This is not the actual code, just used to illustrate the design.
HttpClient docs: http://jakarta.apache.org/commons/httpclient/preference-api.html
Any input would be appreciated.

I don't know the design or intention of the HttpClient but the way you have it designed now is that all users and threads share the same myClient object. Is that what you expected?

Similar Messages

  • Threadsafe servlet code?

    Hi,
    Im developing a sevlet accesing an enterprise system using HTTP. I am using the Apache HttpClient package and have a questing regarding thread safety. The classes are like below:
    EnterpriseClient.java:
    public class EnterpriseClient
    private HttpClient client;
    MultiThreadedHttpConnectionManager connectionManager = null;
    public void create()
    // create a thread safe HttpClient.
    connectionManager = new MultiThreadedHttpConnectionManager();
    client = new HttpClient(connectionManager);
    public String getEnterpriseData(String msisdn)
    PostMethod post = new PostMethod("....");
    String result = post.getResponseBodyAsString();
    return result;
    public String setEnterpriseData(String msisdn, Strign data)
    PostMethod post = new PostMethod("....");
    post.setMessageBody(data);
    String result = post.getResponseBodyAsString();
    return result;
    EnterpriseServlet.java:
    public class EnterpriseServlet extends HttpServlet {
    EnterpriseClient myClient = null;
    public void init() throws ServletException
    myClient = new EnterpriseClient ();
    myClient .create();
    public void doPost(...) {
    // get enterprise data
    String reply = myClient.getEnterpriseData(id);
    // analyze data
    // set enterprise data
    String reply = myClient.setEnterpriseData(id, data);
    Would this code qualify as thread safe? This is not the actual code, just used to illustrate the design.
    HttpClient docs: http://jakarta.apache.org/commons/httpclient/preference-api.html
    Any input would be appreciated.

    I don't know the design or intention of the HttpClient but the way you have it designed now is that all users and threads share the same myClient object. Is that what you expected?

  • Using SingleThreadModel

    Hello
    I'm reading about ways to make my servlets thread safe. As I have learned , there are two main ways,
    using synchronized block around some code or using SingleThreadModel. (Please correct me if wrong).
    My servlets work in an environemnt where data of database is frequently updated, therefore in their doPost() or doGet() method they stablish a connection to database, get the required data, close the connection and use an arraylist to display the result. (Again please feel free to add your comments on how to best go about this)
    Inside servelts, I do not call any classes (all code of access db is directly inside servelt) and just use some local variables for loops and temp storage and such.
    I appreciate your help with two points:
    1. I would like to use SingleThreadModel for a servlet that updates the database; I have read in
    http://www.exampledepot.com/egs/javax.servlet/NoMulti.html?l=rel
    that this is not sufficeint to properly synchronize shared state and developer should do it. Could you please explain what is meant by shared state and how I can do that ?
    2. For servlets that just run queries, I think I should use synchronized block around some code, but I am not sure which parts of code should be contained in it ?
    Moreover , it is advised not to synchronize doPost or doGet methods ...
    Could you please help me understand what is the best strategy to choose to make sure performance is good and all operations are thread safe?
    Thank you very much in advance
    Nicole

    Use of the SingleThreadModel is discouraged for various reasons. I would not recommend that path.
    Probably need more information about what is needed to be synchronized.
    For query only, I would imagine that no synchronization is necessary.
    With regards to thread safety/synchronization/consistency of data there are a few levels to consider.
    1 - Servlet level.
    The standard model is that a servlet is instantiated once, and then runs multiple threads through its "service" method.
    The easiest way to have a threadsafe servlet is to use local variables only. Class attributes in the servlet would be shared by all threads accessing that class, and thus would not be threadsafe.
    public class MyServlet extends HttpServlet{
      private String nonThreadSafeVariable = "hello";
      protected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, java.io.IOException{
        String threadSafeVariable = "world";
    }So if each call to your servlet obtains its own database connection (preferably from a connection pool) runs its queries and closes/returns it, you will not have concurrency issues there.
    In this simple model you don't need to worry about synchronizing things.
    2 - Making it more complicated. Data/Transaction level.
    If you need to ensure read/write consistency - ie read a value from the database, and then write back an updated value without someone getting that same "before" value (updating someones bank account is the classic example) then you need to synchronize around the whole operation.
    So that you lock, read, write unlock. That is probably best done with a database transaction / lock. If doing it in java, then I would implement this in a bean layer outside of the servlets, and have the servlets call that layer.
    Hope this helps some,
    evnafets

  • Pls clarify me about threadsafe and servlet data member

    is this threadsafe if my servlet has data member but only initiated by init() and rest of the methods do read only on this data member.
    e.g.
    public class myServlet extends HttpServlet {
        private String someString;
        public void init() throws ServletException {
            // codes inti someString;
        // rest of methods
        // bleh ...
    }one more question: is that someString is so called servlet instance variable?

    Hi,
    you r going through a wrong way. Try this way
    TABLES: PA9180.
    git_pa9180 TYPE STANDARD TABLE OF pa9180.
    start-of-selection.
    SELECT * FROM PA9180 INTO TABLE GIT_PA9180
    WHERE ENDDA BETWEEN G_PRE_DATE AND SY-DATUM
    AND ZZCASE_NO LIKE 'E%'.
    END-OF-SELECTION.
    NOW LOOP AT THIS INTERNAL TABLE(GIT_PA9180) AND PROCESS IT FOR FURTHER RESULTS
    Hope this solves ur problem.
    Regards,
    Ibrar

  • LDAP Context Initialization Problem in a Servlet's Init method

    Hi
    I have a servlet where I am using the InitialDirContext to Initialize context to a LDAP Server. I have created the context as a static variable. I am initializing the context in the init method and am using the same reference in the service method of the servlet. But if the context fails (due to naming exception and time out) in the init method all my requests in the service method will fail. Is there any way to validate the reference before using the same in the service method.
    Also what is the best approach to initialize the context in a servlet. Whether to initialize in the service method or the init method.
    I would appreciate if anyone can answer the above 2 queries.
    Thanks in advace,
    Ashish

    If you want to use threadsafe objects in doPost/doGet there are two common ways to do this.
    First, create the object in doPost/doGet. This may get expensive depending on the object, but it is 'easy' code and works.
    The second option is to create a pool of objects in the servlet's init() method and to just have doPost/doGet get an object from the pool, use it and return it when done. This take a little more work to code, but the overhead of creating objects is almost eliminated. Look at jakarta/apache commons pool for a quick way to do this.
    If you create on object in init() and use it in doPost/doGet, any time you get two request for the same servlet at the same time you will have synchronization issues that will usually cause problems. There is one instance of each Servlet, so all request for that servlet go through the single instance. Anything in doPost/doGet must be threadsafe.

  • Best practice for Servlet EJB integration

              I'm wondering what the best practice is for Servlet EJB integration in terms of
              caching the home and remote objects. My understanding is that the Home object
              is threadsafe and could therefore be cached as an attribute of the Servlet. This
              would remove the need for a JNDI lookup for each request. Similarly caching the
              ProxyObject would yield further savings. However, I have noticed that most examples
              don't use either of these practices. Why not?
              Thanks in advance,
              Geordie
              

    This has been answered repeatedly. WL allows you to cache JNDI context
              objects, ejb homes and remotes without any problems. (EJB remote interfaces
              must only be used by one thread at a time, but that requirement is provided
              by the EJB spec itself.)
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com
              +1.617.623.5782
              WebLogic Consulting Available
              "Geordie" <[email protected]> wrote in message
              news:3af9579f$[email protected]..
              >
              > I'm wondering what the best practice is for Servlet EJB integration in
              terms of
              > caching the home and remote objects. My understanding is that the Home
              object
              > is threadsafe and could therefore be cached as an attribute of the
              Servlet. This
              > would remove the need for a JNDI lookup for each request. Similarly
              caching the
              > ProxyObject would yield further savings. However, I have noticed that
              most examples
              > don't use either of these practices. Why not?
              >
              > Thanks in advance,
              > Geordie
              

  • Java.io.StreamCorruptedException (APPLET SERVLET Communication)

    Hi There,
    I have an applet which calls the servlet over httpconnection and sends serialized object to the servlet.
    It works fine but during heavy load it throws following exception but the application doesnot break :-
    [8/5/09 7:36:09:498 EDT] 292c510e SystemErr R java.io.StreamCorruptedException
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.io.ObjectInputStream.readObject0(ObjectInputStream.java(Compiled Code))
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.io.ObjectInputStream.readObject(ObjectInputStream.java(Compiled Code))
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.util.HashMap.readObject(HashMap.java:1172)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1003)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java(Compiled Code))
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java(Compiled Code))
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.io.ObjectInputStream.readObject0(ObjectInputStream.java(Compiled Code))
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at java.io.ObjectInputStream.readObject(ObjectInputStream.java(Compiled Code))
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at com.cisco.swc.applications.dlm.servlet.MigrationReportServlet.doPost(MigrationReportServlet.java:53)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
    [8/5/09 7:36:09:499 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.cisco.tools.filter.AccessLogFilter.doFilter(AccessLogFilter.java:114)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.netegrity.was511.filter.ServletFilter.doFilter(ServletFilter.java:72)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1027)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:544)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:210)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:139)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:332)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:254)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:657)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:453)
    [8/5/09 7:36:09:500 EDT] 292c510e SystemErr R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:937)
    Any pointers would be of great help.
    Thanks

    First, your singleton is not threadsafe, second because it's overly complicated. Simply eagerly initialize it.
    Third: why don't you use the Session or a request parameter to handle your data?
    Fourth: are you sure the serialized data is correctly written?

  • Servlet thread safety

    I am new to Java and servlets. I am experimenting with servlets. I have separate process that puts files on my server periodically. I have written a servlet that reads the folder and determines there is a batch of files that need to be uploaded (ftp'd) to another server. I use apache commons ftp to send the files. The batch size varies, sometimes its 1 file, sometimes as many as 5 files. I find that infrequently, the ftp doesn't complete. I have started using log4j and what I find is that my servlet with ftp will send files 1 and 2 correctly, but after the ftp login and starting the ftp on file 3 of 5, my logging suddenly stops and then I start getting logging on file 4. Its as though something has forced it to jump
    I am not seeing any exceptions. I log each part of the ftp process, the connection, the login, changing folders, sending the file, etc. I'm not sure yet if it is always in the same spot in the list of files.
    I'm concerned there may be some concurancy problem. Its almost like I have my web service starts to run and then part way through, another request for the web service interrupts it and takes control. I am using Tomcat.
    Any suggestions? How do I track it.

    Just keep in mind that only one instance of a servlet will be created during application's lifetime and that this instance is been reused among all requests.
    So if you think logically, anything which you assign as servlet instance variable is NOT threadsafe and anything which you assign as method local variable IS threadsafe. That's all.

  • Servlet Instance Variable scope

    Just want to clarify my understanding of instance variables in regards to Servlets.
    public class TestServlet extends HttpServlet
        public String instVariable = "";
    public void processRequest(HttpServletRequest request, HttpServletResponse response)
          instVariable = request.getParameter("param");
          response.sendRedirect( instVariable ) ;
    }If two users both enter the processRequest logic at the same time, is it possible that they will both get the same
    result? My understanding of this was that if they each execute the first line, then each execute the second
    line, each user would be redirected to the same instVariable that was set by the second request.
    What would be the easiest way to stop this from happening? syncronized? ThreadSafe?
    I just want a simple clarification.
    Thanks for the insight.

    If two users both enter the processRequest logic at
    the same time, is it possible that they will both get
    the same
    result? My understanding of this was that if they
    each execute the first line, then each execute the
    second
    line, each user would be redirected to the same
    instVariable that was set by the second request. Yes, it is possible, since there is only one instVariable.
    What would be the easiest way to stop this from
    happening? syncronized? ThreadSafe? The easiest way to avoid that is to simply not use an instance variable. Use a local variable, declared within your processRequest method. Each thread (i.e. each user of the servlet) has its own set of local variables.

  • Get all values from multi select in a servlet

    Hello,
    I have a multi <select> element in a HTML form and I need to retrieve the values of ALL selected options of this <select> element in a servlet.
    HTML code snippet
    <select name="elName" id="elName" multiple="multiple">
    Servlet code snippet
    response.setContentType("text/html");
    PrintWriter out = null;
    out = response.getWriter();
    String output = "";
    String[] str = request.getParameterValues("elName");
    for(String s : str) {
    output += s + ":";
    output = output.substring(0, output.length()-1); // cut off last deliminator
    out.println(output);But even when selecting multiple options, the returned text only ever contains the value of the first selected option in the <select>
    What am I doing wrong? I'm fairly new to servlets
    Edited by: Irish_Fred on Feb 4, 2010 12:43 PM
    Edited by: Irish_Fred on Feb 4, 2010 12:44 PM
    Edited by: Irish_Fred on Feb 4, 2010 2:14 PM
    Edited by: Irish_Fred on Feb 4, 2010 2:26 PM
    Edited by: Irish_Fred on Feb 4, 2010 2:26 PM
    Edited by: Irish_Fred on Feb 4, 2010 2:32 PM

    I am using AJAX.
    I will show you how I'm submitting the <select> values by showing you the flow of code:
    This is the HTML code for the <select> tag and the button that sends the form data:
    <form name="formMain" id="formMain" method="POST">
         <input type="button" id="addOpts" name="addOpts" value="Add Options" style="width:auto; visibility:hidden" onClick="jsObj.addOptions('servletName', document.getElementById('elName'))">
         <br>
         <select name="elName" id="elName" multiple="multiple" size="1" onChange="jsObj.checkSelected()">
              <option value="0"> - - - - - - - - - - - - - - - - </option>
         </select>
    </form>Note that the "visibility:hidden" part of the button style is set to "visible" when at least one option is selected
    Note that "jsObj" relates to a java script object that has been created when the web app starts ( The .js file is included in the .jsp <head> tag )
    The following code is taken from the file: "jsObj.js"
    jsObj = new jsObj();
    function jsObj() {
    //=================================================
         this.addOptions = function(url, elName) {
              var theForm = document.getElementById('formMain');          
              if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
                   xmlhttp=new XMLHttpRequest();
              } else { // code for IE6, IE5
                   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              url += this.buildQueryString(theForm.name);
              xmlhttp.open("POST",url,true);
              xmlhttp.send(null);
              xmlhttp.onreadystatechange=function() {
                   if(xmlhttp.readyState==4) { // 4 = The request is complete
                        alert(xmlhttp.responseText);
    //=================================================
    this.buildQueryString = function(formName) {
              var theForm = document.forms[formName];
              var qs = '';
              for (var i=0; i<theForm.elements.length; i++) {
                   if (theForm.elements.name!='') {
                        qs+=(qs=='')? '?' : '&';
                        qs+=theForm.elements[i].name+'='+escape(theForm.elements[i].value);
              return qs;
         //=================================================
    }And this is a code snippet from the "servletName" servlet:public synchronized void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException,IOException {
              PrintWriter out = null;
              try {
                   response.setContentType("text/html");
                   out = response.getWriter();
                   String output = "";
                   String[] values = request.getParameterValues("elName");
                   for(String s : values) {
                        output += s + ":";
                   output = output.substring(0, output.length()-1); // cut off last delimitor
                   out.println(output);
                   } catch (Exception e) {
         }So anyway, everthing compiles / works, except for the fact that I'm only getting back the first selected <option> in the 'elName' <select> tag whenever I select multiple options
    Edited by: Irish_Fred on Feb 7, 2010 10:53 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Open Jasper Report in new page using servlet

    Guys,
    Looks very simple but i am having problem making this process work. I am using 11.1.1.4
    This is my use case:
    - From a employee page, user clicks on a menu item to open report for current employee. I need to pass appropriate report parameters to servlet and open report into new page.
    I can successfully call servlet using commandmenuitem and set request parameters and call servlet from backing bean.... but that doesn't open report in a new page.... any way i can do this?
    Another option i tried was that using gomenuitem and setting target=blank but in that case i need to pass the parameter using servlet url which i like to avoid.(in case i need to pass many parameters in future) (also values will be set on page so i need to generate url when then click the menuitem...... so there are some hoops and loops i need to go through) I don't know a way to pass the request parameter using backing bean to servlet... i don't think it is possible.
    Those are the two approaches i tried.
    If you have any better approach...I would appreciate if you can let me know. (i have searched on internet for two days now.... for the solution)
    -R
    Edited by: polo on Dec 13, 2011 7:22 AM

    Hi,
    Hope following will useful
    http://sameh-nassar.blogspot.com/2009/10/using-jasper-reports-with-jdeveloper.html
    http://www.gebs.ro/blog/oracle/jasper-reports-in-adf/

  • How can i execute ejb method in a servlet?

    hi
    I am using a IBM HTTP Server and Weblogic Server.
    I could execute below source in a main method of application but i could not that in a init method of servlet because of ClassCastException.
    (a classpath of weblogic contains client's classpath)
    // source code
    Hashtable props = new Hashtable();
    props.pu(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    props.put(Context.PROVIDER_URL,
    "t3://192.168.1.5:7001");
    Context ctx = new InitialContext(props);
    Object obj = ctx.lookup("session.LigerSessionHome");
    LigerSessionHome home = (LigerSessionHome) PortableRemoteObject.narrow (obj, LigerSessionHome.class);
    // error code
    Exception : session.LigerSessionBeanHomeImpl_ServiceStub
    java.lang.ClassCastException: session.LigerSessionBeanHomeImpl_ServiceStub
    at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:253)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:136)
    at credit.getCreditResearch(credit.java:41)
    at creditResearchClient.doGet(creditResearchClient.java:122)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
    thanks

    Have your stubs somehow got out of sync? So that your Servlet engine is pointing to a different jar than that of your jvm on which you were running your client application
    hi
    I am using a IBM HTTP Server and Weblogic Server.
    I could execute below source in a main method of
    application but i could not that in a init method of
    servlet because of ClassCastException.
    (a classpath of weblogic contains client's classpath)
    // source code
    Hashtable props = new Hashtable();
    props.pu(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.jndi.WLInitialContextFactory");
    props.put(Context.PROVIDER_URL,
    "t3://192.168.1.5:7001");
    Context ctx = new InitialContext(props);
    Object obj = ctx.lookup("session.LigerSessionHome");
    LigerSessionHome home = (LigerSessionHome)
    PortableRemoteObject.narrow (obj,
    LigerSessionHome.class);
    // error code
    Exception :
    session.LigerSessionBeanHomeImpl_ServiceStub
    java.lang.ClassCastException:
    session.LigerSessionBeanHomeImpl_ServiceStub
    at
    com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(Porta
    leRemoteObject.java:253)
    at
    javax.rmi.PortableRemoteObject.narrow(PortableRemoteObj
    ct.java:136)
    at credit.getCreditResearch(credit.java:41)
    at
    creditResearchClient.doGet(creditResearchClient.java:12
    at
    javax.servlet.http.HttpServlet.service(HttpServlet.java
    740)
    at
    javax.servlet.http.HttpServlet.service(HttpServlet.java
    865)
    thanks

  • How to call a specific method in a servlet from another servlet

    Hi peeps, this post is kinda linked to my other thread but more direct !!
    I need to call a method from another servlet and retrieve info/objects from that method and manipulate them in the originating servlet .... how can I do it ?
    Assume the originating servlet is called Control and the servlet/method I want to access is DAO/login.
    I can create an object of the DAO class, say newDAO, and access the login method by newDAO.login(username, password). Then how do I get the returned info from the DAO ??
    Can I use the RequestDispatcher to INCLUDE the call to the DAO class method "login" ???
    Cheers
    Kevin

    Thanks for the reply.
    So if I have a method in my DAO class called login() and I want to call it from my control servlet, what would the syntax be ?
    getrequestdispatcher.include(newDAO.login())
    where newDAO is an instance of the class DAO, would that be correct ?? I'd simply pass the request object as a parameter in the login method and to retrieve the results of login() the requestdispatcher.include method will return whatever I set as an attribute to the request object, do I have that right ?!!!!
    Kevin

  • Error while opening Excel report using servlet

    Hi
    I am using a servlet to open an excel report which has multiple sheets . But there is a weird problem when i try to open an excel report with two sheets having the same name .
    Generally when an excel with same sheet names is opened with Microsoft excel , it will open the excel file with a dialog showing error .
    But when i am trying to open through a servlet after that open/save dialog box comes , its sending two requests and that too the second one from another browser . How i am saying that its sending from another browser is , during the second time its not passing the session checks which i placed .....I mean the session for the request doesn't have any data while it was expected to have some data which i placed in Session while logging in .
    Can any one let me know why this is happening ?/

    Refer Note:280376.1 on MetaLink. Hope this will help you resolve the issue.
    Thanks
    Shail

  • Error while opening a Office 2007 Excel (.xlsx) from a Servlet

    Hi All,
    Actually i am trying to open an excel file from a servlet. It works fine when the file format is .xls. But if it is .xlsx it gives the below error.
    "The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?"
    There is a link in the application. When we click the link it calls the servlet. The servlet calls the DAO. The DAO queries the DB and the whole output is stuffed into a StringBuffer and the StringBuffer is written to the ServletOutputStream. I have used
    File newFile = new File("ABC.xslx");
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    I have also included the below in the web.xml file.
    <mime-mapping>
    <extension>xlsx</extension>
    <mime-type>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</mime-type></mime-mapping>
    Kindly help me out.
    Thanks.

    Hi,
    I tried to create an excel through POI 3.5 using a simple java program. I am getting the same error when i try to open it.Below is my code. Kindly let me know the problem.
    I am getting the error ""The file you are trying to open .xlsx is in a different format than specified by the file extension. verify the file is not corrupted and is from trusted source before opening the file. Do you want to open the file now?" when opening the .xlsx file.
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    public class test {
    public static void main(String args[]) throws IOException{
    //ExportLobBean exportLobsForm = null;
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    //ArrayList lobList = ExportLobBO.getArrayList();
    //int length = lobList.size();
    int rowCount=0;
    int count=0;
    HSSFRow headerRow = sheet.createRow((short) 0);
    HSSFRow dataRow = null;
    //Creating Column Names
    headerRow.createCell((short)0).setCellValue("LOB-ID");
    headerRow.createCell((short)1).setCellValue("LOB-NAME");
    headerRow.createCell((short)2).setCellValue("WEIGHT");
    for(int i=0;i<5;i++){
    rowCount++;
    sheet.createRow((short)rowCount);
    //exportLobsForm = (ExportLobBean)lobList.get(count);
    headerRow.createCell((short)0).setCellValue(1);
    //LOGGER.info("Lob id "+exportLobsForm.getStrLobId());
    headerRow.createCell((short)1).setCellValue(2);
    //LOGGER.info("Lob name"+exportLobsForm.getStrLobName());
    headerRow.createCell((short)2).setCellValue(3);
    //LOGGER.info("Lob weight"+exportLobsForm.getStrLobWeight());
    count++;
    File f = new File("c:\\test.xlsx");
    FileOutputStream fos = new FileOutputStream(f);
    wb.write(fos);
    }

Maybe you are looking for

  • Airport Extreme Network Stability Issues

    My airport base station is within cord reach of the only working jack in my house (old house). My den is down the hall, my boarder's down in the basement. We've been suffering from pretty bad connection issues, and there doesn't seem to be any clear

  • Java and MS SQL Server 2000 problem, please help

    please help me. I am using java and MS SQL Server 2000, and I'm trying to access and verify the login. I'm getting the following error message: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index Can any please help in this regard. String use

  • Wesinghouse 19" LCD TV

    We've had a Westinghouse 19" LCD TV for 14 months (two months out of warrantee) and it's already starting to die.  You're watching it and it just goes out, no power. 

  • Problem with FM NAMETAB_GET in Unicode system

    Hi everyone, I'm working in a landscape that has a non-unicode development, non-unicode testing, unicode testing and non-unicode production. The intention is to have a unicode production in the future. I have an application that has been developed to

  • Purchase requisition mandatory for raising a PO

    Hi guys, I am trying to make pr compulsory for my po type. a) i made it compulsory(reqd) in the field selection group. b) maintain the relation between pr type and po c) linked the field selection group to the po type. still cannot make the pr compul