Calling a servlet from another servlet?

Hi
I would like to know that how can I call one Servlet from another Servlet. I have tried getServlet() method of ServletContext but it has been deprecated. I want to call a specific method of the other Servlet, is there any other way?
Thanks

I should have seen it from your previous post :(
Code of Servlet 1:
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException
RequestDispatcher rDispatch = null ;
rDispatch = getServletConfig
().getServletContext().getRequestDispatcher
("/Servlet2") ;
rDispatch.forward(request, response) ;
System.out.println("Back in 1");
I assume Servlets 1and 2 are in same web app and you've mapped your servlet2 to /Servlet2 in your web.xml
make it as
rDispatch = request.getRequestDispatcher("/Servlet2");
rDispatch.forward(request,response);
Nothin's wrong with yer servlet2

Similar Messages

  • 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

  • Different ways to invoke a servlet from another servlets?

    Hello,
    I am a bit confused today. I was thinking about all the ways by which I can invoke a servlet from another servlets. I know it can be done by creating an instance of the 2nd servlet in the 1st one. Is there any other way? such as say.... RequestDispatcher perhaps?
    Here is an example to illustrate my point. I have a login.jsp which submits to login.do. login.do search through database and first authenticate email and then the corresponding password. Now its time for displayGame.do. So here how do i do? if it was a displayGame.jsp then i could have used Redirection or Forward but when it is servlets? Can I still go for Redirection or Forward??
    Thank you for reading this confused post. :-)

    if it was a displayGame.jsp then i could have used Redirection or Forward but when it is servlets?Question: do you know what a JSP becomes when you first run it?
    Answer: a servlet.
    So yes, you can use a RequestDispatcher to forward/redirect to a servlet OR a JSP, whatever you like.

  • How to call a servlet from another servlet

    hi everybody,
    i have a problem, i have to call one servlet from another one.
    Everything works on my pc, but when i install the application on the customer's server i got an error about an Uknown URL followed by the name of the machine.
    Wjat i do is the folloqing :
    String urlString = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+servletName;
    URL url = new URL(urlString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    the variable servletName is the name of the servlet i have to call.
    Is there another way to call the servlet ?
    All the servlet are installed in the same server.
    Any suggestion ?
    Cheers.
    Stefano

    Sweep is correct about requestDispatcher being another approach for inter-servlet delegation; the only issue that i recall with this approach is that it defaults the method of the destination servlet to the one it was called from...for example, calling servlet2 from within servlet1.post() resulted in the dispatcher attempting to utilize servlet2.post() - i believe that i searched for a parameterize solution to no avail :( (ended up handling the request by placing a "fake" doPost() in servlet2 that simply called servlet2.doGet())
    however, if your application is functioning correctly on your pc/webserver then the problem may be external to servlet communication (e.g. client webserver's ports not configured or blocked, missing runtime classes, etc.)
    my suggestion would be to set aside the programmatic concerns for the moment - what is the response if you open a browser on a client's machine and access the URL in question (i.e. http://clientserver:port/stefanoServlet)? If it will not respond to access in this manner then it certainly won't when your application calls for it.
    It's possible that there is a coding error but, given the info supplied, i'd start examining the environment, first. Let us know if you have any luck with the test i recommended or not (please provide abundant detail). Or, if you've found the solution then you may want to post back with a quick blub so the next person knows how to escape the trap.
    D

  • What is the best way to call a servlet from another servlet?

    I have a project with 9 servlets (class project). The way I have been moving from servlet to servlet is like this
    doPost(...)
    {      response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>Functions</title>");
    out.println(f"<form name=frm6 method=post action=/servlet2");
    out.println("<input type=submit name='btn' value='servlet2'>");
    out.println("</form>");
    So I have these 9 servlets - I call any 8 of them from the first servlet so I have 8 buttons on 8 forms <form=frm1, frm2, ...frm8 method = post...> But when I bring up the first servlet only 6 buttons show up. I was thinking about using hyperlinks instead, but I would like to do this with buttons. I wanted to do this with javascript and the location object, but I was advised to use jsp. I just want to move from one servlet to the next. Any suggestions appreciated for the best/preferred method for moving from one servlet to the next.
    Thanks

    I think you may need some clarification of terminology etc..
    First off, JSP isn't an alternative to javascript, it's an alternative to coding a servlet. A JSP is a mixture of java code and HTML and is translated into a servlet by the system. JSPs are primarilly for generating HTML pages with variable content. JSPs very frequently generate HTML which includes Javascript.
    You probably shouldn't think of what you're doing as one servlet invoking another, that does happen; a servlet can transfer an transaction to another servlet or JSP. In fact it's standard practice that a servlet does the logical stuff (like interpretting form data) then transfers to a JSP to generate the response page. However in this case it's the browser that can invoke one of the 8 servlets, the first servlet merely creates the page from which they are invoked.
    It's not obvious why only some of your buttons are showing up. In a case like this use the "view source" option on your browser to find out what HTML the servlet is actually delivering. What's wrong should be evident from that.
    You can put a hyperlink arround a button, or an image. Mostly people turn up their noses at the buttons supplied by HTML and use their own images for buttons. You
    can do somthing like this:
    <img src="/images/button3.png" border="0">
    (Of course this arrives as a GET transaction not a POST).
    Or you can do a bit of javascript like:
    <img src="/images/button3.png" style="Cursor: pointer;"
    onclick="document.locations.href='/servlet3';">

  • Calling a method from another servlet? very beginner

    I am going to try to explain what I want to do so just be patient please.
    I want to call a method in a seperate servlet to connect and release my connection pool - How do I do this?
    This is what I have been trying... help
    dbPOOL.class
    package DATABASE;
    import javax.naming.*;
    import javax.sql.*;
    import java.sql.*;
    import java.util.*;
    public class dbPOOL {
      Connection con;
      private boolean conFree = true;
      private String dbName = "java:comp/env/jdbc/connectDB";
      public dbPOOL() throws Exception {
           try  {              
                    InitialContext ic = new InitialContext();
                    DataSource ds = (DataSource) ic.lookup(dbName);
                    con =  ds.getConnection();    
         } catch (Exception ex) { throw new Exception("Couldn't open connection to database: " + ex.getMessage());
      public void remove () {
             try {
                 con.close();
            } catch (SQLException ex) { System.out.println(ex.getMessage());}
      protected synchronized Connection getConnection() {
             while (conFree == false) {
                     try {
                             wait();
                     } catch (InterruptedException e) {
                  conFree = false;
                  notify();
                  return con;
        protected synchronized void releaseConnection() {
            while (conFree == true) {
                     try {
                        wait();
                     } catch (InterruptedException e) {
                  conFree = true;
                  notify();
    }and my worker servlet connTest
    package DATABASE;
    import javax.naming.*;
    import javax.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    public class connTest extends HttpServlet {  
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, SQLException, IOException {
             try {
                    String selectStatement = "select * " + "from mt.Evendale_Web_Groups";
                    getConnection();
                    PreparedStatement prepStmt = con.prepareStatement(selectStatement);
                    ResultSet rs = prepStmt.executeQuery();
                    while (rs.next()) {
                       groupList gl = new groupList(rs.getString(1), rs.getString(2), rs.getString(3));
                    prepStmt.close();
            } catch (SQLException ex) { throw Exception(ex.getMessage());}
                releaseConnection();
    }When I try to compile the connTest servlet - I keep getting cannot find symbols errors on the methods. How do I fix this?

    Which errors exactly?
    Try something like this:
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    dbPOOL db = null;     
    try {               
    String selectStatement = "select * " + "from mt.Evendale_Web_Groups";
    db = new dbPOOL();        
    Connection con = db.getConnection();               
    PreparedStatement prepStmt = con.prepareStatement(selectStatement);               
    ResultSet rs = prepStmt.executeQuery();               
    while (rs.next()) {                                    
       // process your rs                      
    prepStmt.close();           
    } catch (Exception ex) {
    } finally {
        if (db != null)
             db.releaseConnection();             
    }Simply change the package name to something else. But don't forget to import your dbPOOL class since it is now located in a diff package. Also be aware of coding standards when naming your classes and packages.

  • Calling one Servlet from another servlet

              First servlet...............>
              package javaservlets.samples;
              import javax.servlet.*;
              import javax.servlet.http.*;
              public class TableElements extends HttpServlet{
                   public void doGet(HttpServletRequest request,HttpServletResponse response)
                   throws ServletException,IOException{
                        response.setContentType("text/plain");
                        try{
                             RequestDispatcher rd = getServletContext().getRequestDispatcher("/TableFilter");
                             if(request==null){
                                  System.out.println("Request null...");
                                  System.exit(0);
                             if(response == null){
                                  System.out.println("Response null...");
                                  System.exit(0);
                             if(request!=null&&response != null){
                             System.out.println("Both are not null...");
                             rd.forward(request,response);
                        }catch(ServletException se){
                             se.printStackTrace();
                        }catch(IOException ioe){
                             ioe.printStackTrace();
              Second Servlet..............>
              package javaservlets.samples;
              import javax.servlet.*;
              import javax.servlet.http.*;
              public class TableFilters extends HttpServlet{
                   public void service(HttpServletRequest request,HttpServletResponse response)
                   throws IOException,ServletException{
                        String type = request.getContentType();
                        System.out.println("type : "+type);
              from the TableElement servlet just I am calling the TableFilter servlet and in
              the TableFilter I am trying to print the request content type. But I am getting
              NULL. i was supposed to get "TEXT/PLAIN".
              can any one tell what is the problem.
              very urgent.
              thanx in advance
              

    Your example seems to assume that the reponse of the first servlet becomes
              the request in the second servlet let this is not so. After the forward the
              request and response obejcts are the same as before the forward, except the
              referer attribute is changed.
              "Gururaj Kosigi" <[email protected]> wrote in message
              news:[email protected]...
              >
              > First servlet...............>
              >
              > package javaservlets.samples;
              >
              > import javax.servlet.*;
              > import javax.servlet.http.*;
              >
              >
              > public class TableElements extends HttpServlet{
              >
              >
              >
              > public void doGet(HttpServletRequest request,HttpServletResponse response)
              > throws ServletException,IOException{
              >
              > response.setContentType("text/plain");
              >
              >
              > try{
              >
              > RequestDispatcher rd =
              getServletContext().getRequestDispatcher("/TableFilter");
              >
              > if(request==null){
              > System.out.println("Request null...");
              > System.exit(0);
              > }
              > if(response == null){
              > System.out.println("Response null...");
              > System.exit(0);
              > }
              > if(request!=null&&response != null){
              > System.out.println("Both are not null...");
              > }
              >
              > rd.forward(request,response);
              > }catch(ServletException se){
              > se.printStackTrace();
              >
              > }catch(IOException ioe){
              > ioe.printStackTrace();
              >
              > }
              >
              > }
              > }
              >
              > Second Servlet..............>
              >
              > package javaservlets.samples;
              >
              > import javax.servlet.*;
              > import javax.servlet.http.*;
              >
              >
              > public class TableFilters extends HttpServlet{
              >
              > public void service(HttpServletRequest request,HttpServletResponse
              response)
              > throws IOException,ServletException{
              >
              >
              > String type = request.getContentType();
              > System.out.println("type : "+type);
              >
              > }
              > }
              >
              > from the TableElement servlet just I am calling the TableFilter servlet
              and in
              > the TableFilter I am trying to print the request content type. But I am
              getting
              > NULL. i was supposed to get "TEXT/PLAIN".
              >
              > can any one tell what is the problem.
              > very urgent.
              >
              > thanx in advance
              

  • Calling a servlet from a servlet?

    Is it possible to call one servlet from another servlet?

    You should use servlets to process requests. If what you're asking for is to execute a piece of logic within a servlet before its finished processing the request, then you should consider using a regular java class instead of a servlet. If you just want to send the request information to another servlet you can use getRequestDipatcher().forward(..) method. Keep in mind that by doing so you'll interupt the current servlet.
    Regards,
    D.

  • How to call a Applet from a servlet and vice versa...?

    Hi all
    Can anyone help me how to call a applet from a servlet and vice versa. When the applet is called it should contact the database (oracle8i) and get the data. When i submit the applet form the data in the applet should be saved in the database.
    Thanks in advance
    Kamalakannan

    Sweep is correct about requestDispatcher being another approach for inter-servlet delegation; the only issue that i recall with this approach is that it defaults the method of the destination servlet to the one it was called from...for example, calling servlet2 from within servlet1.post() resulted in the dispatcher attempting to utilize servlet2.post() - i believe that i searched for a parameterize solution to no avail :( (ended up handling the request by placing a "fake" doPost() in servlet2 that simply called servlet2.doGet())
    however, if your application is functioning correctly on your pc/webserver then the problem may be external to servlet communication (e.g. client webserver's ports not configured or blocked, missing runtime classes, etc.)
    my suggestion would be to set aside the programmatic concerns for the moment - what is the response if you open a browser on a client's machine and access the URL in question (i.e. http://clientserver:port/stefanoServlet)? If it will not respond to access in this manner then it certainly won't when your application calls for it.
    It's possible that there is a coding error but, given the info supplied, i'd start examining the environment, first. Let us know if you have any luck with the test i recommended or not (please provide abundant detail). Or, if you've found the solution then you may want to post back with a quick blub so the next person knows how to escape the trap.
    D

  • Calling a WS from a servlet...EndpointPort does not contain operation meta.

    Hi all,
    I'm trying to call a service from a servlet but I get an error:
    Error: Endpoint {http://com.susan/SusanWS}SusanWebServiceEndpointPort does not contain operation meta data for: LoginWebService
    ...the WS is up and running (of this I'm sure...cause I also tested it with soapui...and it works..)
    The webservice is running on a local jboss (to which i can successfully connect, and see the wsdl...).
    the servlet is running on a local tomcat (which is also ok...).
    I'm trying to call the WS like this:
    Service service = new Service();
    Call call = (Call)service.createCall();
    call.setTargetEndpointAddress( new URL( wsEndpoint ) ); //http://localhost:8080/webservices/SusanWS (the same I used in soapui...so it should be right)
    call.setOperationName( "LoginWebService"); //name of the method i want to use...
    call.addParameter( "appCode", Constants.XSD_STRING, ParameterMode.IN );
    call.addParameter( "login", Constants.XSD_STRING, ParameterMode.IN );
    call.addParameter( "passwd", Constants.XSD_STRING, ParameterMode.IN );
    //            call.setReturnType( Constants.XSD_INT ); //left this out...should be the cause...
    Object retval = call.invoke( new String[] { appCode, login, passwd} ); //appCode,login,passwd contain the strings i want to  forward as input.if I try to run it I get(in the jboss log...):
    15:41:55,594 ERROR [SOAPFaultExceptionHelper] SOAP request exception
    javax.xml.rpc.soap.SOAPFaultException: Endpoint {http://com.susan/SusanWS}SusanWebServiceEndpointPort does not contain operation meta data for: LoginWebService
    at org.jboss.ws.server.ServiceEndpointInvoker.getDispatchDestination(ServiceEndpointInvoker.java:181)
    at org.jboss.ws.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:107)
    at org.jboss.ws.server.ServiceEndpoint.handleRequest(ServiceEndpoint.java:209)
    at org.jboss.ws.server.ServiceEndpointManager.processSOAPRequest(ServiceEndpointManager.java:355)
    at org.jboss.ws.server.StandardEndpointServlet.doPost(StandardEndpointServlet.java:115)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.jboss.ws.server.StandardEndpointServlet.service(StandardEndpointServlet.java:76)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)
    don't know if it can help...the soapui request looks like this:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://com.susan/SusanWS/types">
    <soapenv:Header/>
    <soapenv:Body>
    <typ:LoginWebService>
    <LoginInfo_1>
    <appCode>WEB_SERVICES</appCode>
    <login>root</login>
    <passwd>root</passwd>
    </LoginInfo_1>
    </typ:LoginWebService>
    </soapenv:Body>
    </soapenv:Envelope>
    anybody has an idea of what I'm doing wrong?
    Edited by: Turbo-555 on Mar 18, 2009 8:36 AM

    if I change the code with:
    //call.setOperationName( wsMethod );
    call.setOperationName( new QName("http://com.susan/SusanWS",wsMethod)); //http://com.susan/SusanWS is the targetnamespace...the error changes into:
    16:55:21,051 ERROR [SOAPFaultExceptionHelper] SOAP request exception
    javax.xml.rpc.JAXRPCException: Cannot find child element: {http://com.susan/SusanWS/types}LoginWebService
    at org.jboss.ws.binding.soap.SOAPBindingProvider.getParameterFromMessage(SOAPBindingProvider.java:799)
    at org.jboss.ws.binding.soap.SOAPBindingProvider.unbindRequestMessage(SOAPBindingProvider.java:282)
    at org.jboss.ws.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:112)
    at org.jboss.ws.server.ServiceEndpoint.handleRequest(ServiceEndpoint.java:209)
    at org.jboss.ws.server.ServiceEndpointManager.processSOAPRequest(ServiceEndpointManager.java:355)
    at org.jboss.ws.server.StandardEndpointServlet.doPost(StandardEndpointServlet.java:115)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.jboss.ws.server.StandardEndpointServlet.service(StandardEndpointServlet.java:76)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)

  • Can I call a "function" from a servlet?

    A few of my servlets need to perform about the same computations (have large sections of identical code).
    It would save some disk space to be able to call a procedure from different servlets.
    Can this be done? How?
    Thank you all.

    A few of my servlets need to perform about the same
    computations (have large sections of identical code).
    It would save some disk space to be able to call a
    procedure from different servlets.
    Can this be done? How?This wouldn't be the way to do it.
    Since Java is an object oriented programming language, you should use it's concepts to implement a 'basic' class and than extend it. This means: Create a class that contains the basic procedures (you will never create an instance of this class) and then create all the serlvet classes by extending the 'mother' class. Like this you have the common code once in the 'mother' class and the specific code in the specific servlets.

  • Calling second servlet from first servlet

    I need to call a servlet from a servlet.
    I need to call the specific doGet method of servlet 2 from
    servlet 1. I also need to return the control to servlet 1
    after servlet 2 done its job.
    I did it now by creating a new instance of servlet 2 from servlet1
    and then call the doGet method like
    in servlet1 : Servlet2 serv2 = new Servlet2();
    I really don't like this idea of creating a new instance in servlet 1.
    Any thoughts/idea/comments would be appreciated.

    request.getRequestDispatcher("path/to/otherServlet").forward(request, response);
    or
    request.getRequestDispatcher("path/to/otherServlet").include(request, response);will do what you are looking for. See the API documentation on details. Basically the difference is that forward gives FULL control (including that of the headers) to the invoked servlet while include mearly "includes" the results.

  • CallerPrincipal when calling one sessionbean from another

    Hi all,
    I have a little problem when calling one sessionbean from another sessionbean. The problem is, that in the method, which is called, is used SessionContext's getCallerPrincipal().getName(). This works great from client, but from other sessionbeans getCallerPrincipal() retuns an "ANONYMOUS" principal. How can I set the correct principal (the principal from the first sessionbean)?
    Thank you
    My env: Glassfish 2.1.1, Netbeans 6.8, Eclipselink 2.0.0, Java 1.6.0.18
    My code:
    @Stateless
    public class ABean implements ASessionRemote{
    @Resource
    SessionContext ctx;
    @Override
    public void aMethod(){
    String name = ctx.getCallerPrincipal().getName(); // the name is ANONYMOUS, when the call is done from other sessionbean
    @Stateless
    public class BBean implements BSessionRemote{
    @Resource
    SessionContext ctx;
    @EJB
    private ASessionRemote aSessionBean;
    @Override
    public void bMethod(){
    aSessionBean.aMethod();
    }

    "This works great from client"
    What do you mean by this, i.e what sort of client are you using (stand alone app, servlet) ?
    what shows up if you printout the caller principal in the calling bean ?
    are the two ejbs in the same ear ?
    what security meta-information are you using in ejb-jar.xml and sun-ejb-jar.xml, if any ?

  • Passing parameter value via href in a servlet to another servlet

    Hi
    I have this issue with passing a value from one servlet to another servlet. the situation is is this.
    i have a servlet tstret.java which say..pulls out all the employee_id(s) from a table and displays it as hyperlinks( using the anchor tag.).
    now when i click on the hyperlink say T001 , The control is passed to another servlet which pulls out all the info about employee id T001.
    the problem i have is in the tstret.java servlet. i am passing the employee_id as a parameter in the href path itself as shown below.
    out.println("<td ><a href=\"http://localhost:7000/servlets-examples/accept_requisition.html?id="+[u]rs.getString(1)[/u]+"\" ><em>"+rs.getString(1)+"</em></a></td>");now if you see the code i am trying to pass the employee_id by attaching it to a variable id and passing it with the url, it gives me a sql exception saying no data found .
    if i pass a string say "rajiv" which i defined at the begining of code then i am able to pass it to the next servlet/html.
    the full code is as follows
    file : tstret.java
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class tstret extends HttpServlet
         PrintWriter out;
         String[] employee_identity;
         public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
              try
              response.setContentType("text/html");
              out = response.getWriter();
              String session_name="SHOBA";//request.getParameter("session_name");
              out.println("<html><head><title> My Jobs </title></head>");
              out.println("<body bgColor=#ececec leftMargin=10>");
              out.println("<table align=center>");
              out.println("<tr align=center><td><img src=\"http://localhost:7000/servlets-examples/images/topbar.gif\"></td></tr>");
              out.println("<td>Jobs for : "+session_name+"</td>");
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection connection = DriverManager.getConnection("jdbc:odbc:tst","scott","tiger");
              Statement statement=connection.createStatement();
              ResultSet rs= statement.executeQuery("select req_no from require_info where sent_to = " + "\'" + session_name + "\'");
    //          out.println("Jobs for : "+session_name);
              while(rs.next())
              /*     String[] get_id={"shoba","ping","ting","ving"};
                   for(int i=0;i<get_id.length;i++)
                   out.println(" <tr align=\"center\">");
              //     out.println("<td><a href=\"servlet/testhyper\" name="+rs.getString(1)+"><em>"+rs.getString(1)+"</em></a></td>");
                   out.println("<td ><a href=\"http://localhost:7000/servlets-examples/accept_requisition.html?id="+rs.getString(1)+"\" ><em>"+rs.getString(1)+"</em></a></td>");
                   out.println("</tr>");
                   out.println("<br>");
              }catch(SQLException se){out.println("sqlexception"+se);}
              catch(ClassNotFoundException ce){out.println("cnfexception"+ce);}
              out.println("</table></body></html>");
         public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
              doGet(request, response);
              Can some one help me and see if there is anything i missing or doing wrong.
    thanks in advance

    Try storing the id at the top of the loop, then using that for the URL and the link text, instead of calling rs.getString(1) twice:
      while(rs.next())
        String emp_id = rs.getString(1);
        out.println(" <tr align=\"center\">");
        out.println("<td ><a href=\"accept_requisition.html?id="+emp_id+"\" ><em>"+emp_id+"</em></a></td>");
        out.println("</tr>");
        out.println("<br />");
      }

  • Calling a report from another report

    Hi,
    Is there any way ,(any built in ) to call a report from another report in Report Builder 2000 and Report Builder 6i.
    Regards

    Try to call report from report by a button in the calling report:
    1     In the Layout Model view, click in the tool palette. Note
    2     Click and drag a rectangle.
    3     Double-click the button object to display the Property Palette.
    4     Under the Button Label node, set the Label Type property to either Text or Icon:
    n     If the button label is text, set the Text property to the text you want to appear on the button.
    n     If the button label is an icon, set the Icon Name property to the name of the file containing the icon (the file must reside in the directory specified by the UI_ICON environment variable).
    5     Under the Button Behavior node, set the Type property to PL/SQL.
    6     Double-click the PL/SQL Trigger property value field.
    7     In the PL/SQL Editor, define the PL/SQL for the action trigger or format trigger when the button is clicked in the formatted report.
    8     Set other properties as desired.
    9     To activate the button, run the report, then display it in the Runtime Previewer.

Maybe you are looking for

  • Printing issue in iTunes 7

    I'm trying to print songs by album from my Music Library on my PC. I print it to PDF file ... it prints ok the only problem I have is that there are only 17 pages of Music but after page 17 it is all blank pages upto 97? Does anyone know what the pro

  • Can't open a Word document in Pages '09

    Alright...I have tried to search the forum to see if someone is having the same problem but I haven't seen any. I cannot open a word document in pages. at all. Just says "The document "filename.doc" couldn't be opened." Any suggestions?

  • Math.random() function in Java

    My computer doesn't gives enough good random numbers with this function. Does it need any improvement?

  • Apple should make iTunes Match management better.

    When you play a song on your phone via iTunes Match, the audio file still on the phone, so it can be played offline on the go. The problem is, the cloud button still appearing and theres no way to delete those songs in order to set free space. I crea

  • CCR error code 168-Diff in content

    Hi, We are finding many orders with CCR error code-168 diff in content. After resending data to APO these are not getting corrected. When checked randomly most of these orders are overdelivered. ie. delivered quantity more than order quantity. How to