Passing Attribute in Request Dispatcher

Hi,
I am using servlet#1 to pass the value of an Attribute to servlet#2
servlet #1 code
ServletContext sc = getServletContext();
request.setAttribute("name",value);
RequestDispatcher rd = sc.getRequestDispatcher(url);
rd.forward(request, response);
servlet #2 code
ServletContext sc = getServletContext();
String string = (String) sc.getAttribute("name");
when I run servlet #1 request dispatcher forwards request and response to servlet #2 but the Attribute value is not passed along
what am I missing ?
thanks VERY much for your response in advance and past responses !!
Rick

Hi rickdd,
In servlet #2 you should get the value from
servlet's Request object rather than ServletContext,
because parameter is set with Request Object not with
ServletContext.
So modifiy the code as given below...
     /* Parameter is passed with servlet's Request Object.
      * So Next line needs to be commented.
     //ServletContext sc = getServletContext();
     //Here get the value from servlet's Request Object
     String string = request.getAttribute("name");
   This will work.
Regards
Goodieguy

Similar Messages

  • Cant pass attributes in request

    I'm trying to pass attribute to jsp in my JSPProvider -
    Vector list = new Vector();
    list.add(new MyUser("Name1"));
    req.setAttribute("list",list);
    where MyUser is a simple class -
    package custom;
    public class MyUser {
    private String name;
    public MyUser(String name) {
    this.name = name;
    when i'm trying to extract attribute in jsp -
    Vector list = (Vector) request.getAttribute("list");
    for(int i=0;i<list.size;i++)
    MyUser myuser = (MyUser) list.get(i); ---exception occured here - ClassCastException.
    if i write in jsp
    Object o = list.get(i);
    out.println(o.toString());
    the output is - custom.MyUser@3af4b3
    what is the matter???

    even tough you made a workaround for your problem i
    still find it very strange the getParameterValues
    returns a String and not a String arrayHi pgeuens,
    You were right. when i am passing the array from the first jsp its getting passed an a comma separated list. though i have declared the variable as an array. in the first jsp if i access the array element wise it gives the correct output but when i just give the variable name without giving the element id i simply get a comma separated list. i dont know why that is happening. can you suggest something

  • Passing attributes between providers and portlets

    When using Providers, it is possible to pass session data between providers via ProviderContext.setSessionProperty. Is it possible to pass attributes from a provider to a portlet? Anything set on the ProviderContext does not seem to get propagated to the portlet via PortletSession.getAttribute(). Similarly the attributes set on the provider's request object to not seem to be propagated to the PortletRequest.

    My understanding is that Providers are the Sun proprietary portal technology, predating JSR 168 and Portlets.
    You can use Portlets to implement leaf channels ... but you must still write Providers if you want to fiddle with containers.

  • Request dispatch problem

    To all
    The problem is that my request dispatching is not forwarding the request and I haven't got a clue why. I have a upload servlet which is working fine as it parses the request and the forwards you to the same jsp page or the next jsp page according to what values it extracts. However I have set up a bean to display the contentType() of each request which is sent to it from the jsp pages, however nothing is displayed when the request is forwarded from the upload servlet. this is what is happening .....
    public class upload extends HttpServlet {
    public void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {
    HttpServletRequest request = _req;
    HttpServletResponse response = _res;
    parseMultiForm pMF = new parseMultiForm( _req );
    Hashtable values = new Hashtable();
    String param;
    while ( ( param = pMF.getNextParameter()) != null) {
    String value = pMF.getParameter();
    values.put(param, value);
    if (values.containsKey("submit")) {
    String url = (String) values.get("reload");
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/" + url);
    dispatcher.forward(request, response);
    if (values.containsKey("continue")) {
    String url = (String) values.get("next");
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/" + url);
    dispatcher.forward(request, response);
    The above servlet forwards the request to a jsp which does the following....
    <jsp:useBean id="info" scope="session" class="InfoBean" />
    <jsp:setProperty name="info" property="request" value="<%= request %>" />
    However infoBean does not receive anything when the request is forwarded from the servlet??
    Can anyone see anything obviously wrong?? is it to do with the JSP asking for the <%= request> and not receiving it because the request dispatcher has altered it in some way?
    Thanks in advance anyone
    Andy.

    I have exactly the same problem. I can�t make the servlet pass the request object to the target jsp.
    Try not changing the request nor the response. Unfortunatelly due to the kind of job i do inside my servlet there's no way i can't touch the request. So if you can make it work with mi advice please let me know.

  • How to pass a HTTP request from a simple java class

    Is it possible to pass an HTTP request from a simple java class.if yes how?

    Is it possible to pass an HTTP request from a simple
    java class.if yes how?If you're talking about creating a HttpRequest object and passing it to a servlet, that would be a red flag to me that your design is flawed. You shouldn't have to do that - the application server (Tomcat, Weblogic, etc) should be the only thing that has to worry about creating that kind of object and passing it to you.

  • Query Strings in Request Dispatcher Paths (PLT.16.1.1)

    I'm having trouble using query strings in a request dispatcher include to a servlet.
    I'm spitting debug out, and it looks like I'm calling:
    PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/myServlet?myparam=myparamValue");
    And myparam isn't being set for myServlet.
    The same URL ("http://myhost:myport/myPortal/myServlet?mayparam=mayparamValue)
    runs fine standalone....

    I'm not sure of the exact dates (either this month or the next). But
    JSR168 will be supported in the service pack.
    Subbu
    T-Bone said the following on 11/18/2003 09:23 AM:
    Subbu Allamaraju <[email protected]> wrote:
    There is a known bug in WLS's servlet container that results in this
    behavior. Please contact support if you need an expedited solution.Thanks, they said to wait for SP2 sometime end of November.
    Can you tell me when it will be available?
    Also, when will JSR-168 v1.0 be supported?
    Subbu
    T-Bone said the following on 10/26/2003 03:14 PM:
    I'm having trouble using query strings in a request dispatcher includeto a servlet.
    I'm spitting debug out, and it looks like I'm calling:
    PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/myServlet?myparam=myparamValue");
    And myparam isn't being set for myServlet.
    The same URL ("http://myhost:myport/myPortal/myServlet?mayparam=mayparamValue)
    runs fine standalone....

  • Attributes of request do not match buffer attributes

    Hi all,
    I created a connector of the type 'SAP File Search' in the Enterprise Search Cockpit. But the connector cannot be setted to an active status and when i'm executing the consistency check i get the error message "Attributes of request xx, connector yy do not match buffer attributes".
    Can someone give me some recommendation ?
    Kind regards
    Patricia Wolf

    I haven't found an answer to this yet and wish I could give advice.
    However, I'm looking for it. And if you find anything - we'd love to know.
    I've got a very large progect - all the media was manually copied over (via the finder) to external lacie FW drives which were brought here to another satellite editing room. I recieve updated projects from the primary edit and relink the media - The audio files have tended to 'mismatch' when I reconnect the updates. And it appears this is increasing in frequency each time! (I relink to each new version of the project which is sent).
    At this point it seems all the audio files bring up the same "File Attribute Mismatch" window. Only in certain sections of the sequence is the audio out of sync (to a variable degree +/- 5 to 7 frames).
    This occours when I replicate the workflow on another machine.
    This does NOT happen when I've sent the projects back to the original edit suite - which has the original media. The reconnection is fine.
    So it appears this might be due to the media itself - and possibly when it was copied over.
    But I can't yet figure out why this problem appears to be increasing, occouring with more audio files.
    If anyone has any ideas to this - which sounds very similar to the original issue on this thread - we'd be obliged to reciprocate the help!
    Cheers
    G5 dual 2.3GHz power PC   Mac OS X (10.4.6)   FCP 5.0.4 / QT 7.1
    12 G4 PowerBook (1Ghz)   Mac OS X (10.4.1)  

  • Urgent, creating xml files dynamically, request dispatcher problem

    hi all,
    Problem 1:
    There is a problem we are facing, while request dispatching.
    The files CBECBC.XML & CBECBC_Envelop.XML,
    both xml files. These files are created on request from the user, dynamically, and displayed on the browser,
    by including them in a jsp page.
    Here we face a problem when they are to be included into the jsp page.
    The error is the following :
    //////// Error ////////
    Could not find request dispatcher for the url CBECBC.xml
    Could not find request dispatcher for the url CBECBC_Envelop.xml
    The created files are stored in the "d:\pstudio35\desks\bank\BankWeb\".
    We are using " <jsp:include page="...."/> " (dynamic jsp include tag), to include the xml files.
    Problem 2:
    And could you just let me know how to include a xml file in a jsp file,
    so that the xml file is displayed in the exact format of xml(with the tags).
    I am using Pramati Studio 3.5
    Its urgent!!!
    Regards,
    Deepa Datar

    problem 2:
    either translate all < en > into < and > or display the XML in a textarea

  • Nested request dispatches when using RequestDispatcher in a Button action

    Hi all,
    I am new to JSF so I am probably missing something very simple, please help:
    The test case is simple: I created one visual web page with one button and one normal JSP file(named test.jsp) using Netbeans 5.5 with visual web pack on Sun Application Server 9 PE. The code action for the button is as follows:
    public String button1_action() throws Exception
            ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
            HttpServletRequest request = (HttpServletRequest) context.getRequest();
            HttpServletResponse response = (HttpServletResponse) context.getResponse();
            RequestDispatcher dispatcher = request.getRequestDispatcher("test.jsp");
            dispatcher.forward(request,response);
            return null;
        }Once the JSF page is loaded and the button is clicked, this exception occurs:
    ApplicationDispatcher[WebApplication1] Servlet.service() for servlet Faces Servlet threw exception
    javax.servlet.ServletException: WEB2651: Exceeded maximum depth for nested request dispatches: 20
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:837)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:697)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:532)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:465)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:353)
    at webapplication1.Page1.button1_action(Page1.java:242)
    Can anyone provide any advice on how to resolve this issue?

    Hi Rachel,
    As per the Servlet2.3 Javadoc:
    The pathname must begin with a "/" and is interpreted as relative to the current context root.
    If you make that change and include the complete path, then it would work fine.
    Ex:
    If your context looks like http://my.company.com/webapp1/ and if you were to have your forwardPortlet.jsp in a directory like:
    webapp1
      |
      |-> htdocs
             |
             |-> forwardPortlet.jsp
    then, your code would look like;
    RequestDiscpatcher d = request.getRequestDispatcher("/htdocs/forwardPortlet.jsp");
    HTH,
    thanks,
    harsha

  • How to pass attribute values through variables in JSP  Custom TagLib

    Hi,
    Can anybody help me how to pass values through varuables in the jsp custom tag.
    i am using JSP custom tag. I am unable to pass attribute values through variables.
    <invitation:invdetails invid="<%=invid%>"/> The value is passing as <%=invid%> ,not value of the invid.
    But i am getting throuh the fllowing
    <invitation:invdetails invid='1' />
    Please anybody suggest me how to pass value by using the variable.

    Hi,
    It sounds like you need to set the <rtexprvalue> tag to true in the TLD for your tag. If you do this the tag will read in the value you are trying to pass to it.
    dapanther...

  • Request dispatcher null

              The forward code we have is like
              public void forward(String url, HttpServletRequest request,
              HttpServletResponse response)
              throws ServletException, IOException
              RequestDispatcher dispatcher = getServletConfig().getServletContext().getRequestDispatcher(url);
              dispatcher.forward(request, response);
              My question is:
              As per the documents
              The pathname must begin with a "/" and is interpreted as relative to the current
              context root.
              if my URL is "http://www.abcz.com/<somepage>
              request dispatcher is null? and on one server (say A) that is a problem but other
              server(say B) when given the full URL behaves ok.
              on server A I am getting a null pointer exception , which on tracing happens to
              be the request dispatcher is null.(If http://www.abcz.com/<somepage> is URL) but
              no null pointer exception if url is "/<somepage>"
              On B its behaving fine when given the "http://www.abcz.com/<somepage> " as URL
              to the method.
              Both server A and B are running wl6. Is the difference in service pack cause of
              the problem?
              Internally does wl6 parses the URL to find a relative URL?
              Any help will be greatly appreciated.
              Thanks
              Rumpa
              

    And the reason for that is, RequestDispatcher is per application
              scope. And RequestDispatcher comes from the ServletContext which is
              the current application scope. So it has to be relative url. If you
              need to forward to an absolute url, you can use sendRedirect instead.
              Bhaskar
              "Matt Krevs" <[email protected]> wrote in message news:<[email protected]>...
              > as far as i know, you should always specify relative urls when using request
              > dispatchers
              >
              > eg
              >
              > if the entire url is
              > http://myserver/theurl
              > you would code as follows
              >
              > RequestDispatcher dispatcher =
              > getServletConfig().getServletContext().getRequestDispatcher("/theurl");
              > dispatcher.forward(request, response);
              >
              > You definitely should not use complete URLs when calling
              > getRequestDispatcher()
              >
              > what happens on the server that returns a null dispatcher if you manually
              > type the address into the browser? Does weblogic find the resource? If not
              > then you have something specified differently in your server that doesn
              > work.
              >
              >
              > "RUMPA GIRI" <[email protected]> wrote in message
              > news:[email protected]...
              > >
              > > The forward code we have is like
              > > /**********************************************/
              > >
              > > public void forward(String url, HttpServletRequest request,
              > > HttpServletResponse response)
              > > throws ServletException, IOException
              > > {
              > > RequestDispatcher dispatcher =
              > getServletConfig().getServletContext().getRequestDispatcher(url);
              > > dispatcher.forward(request, response);
              > > }
              > > /***********************************************/
              > >
              > > My question is:
              > > As per the documents
              > > The pathname must begin with a "/" and is interpreted as relative to the
              > current
              > > context root.
              > > if my URL is "http://www.abcz.com/<somepage>
              > > request dispatcher is null? and on one server (say A) that is a problem
              > but other
              > > server(say B) when given the full URL behaves ok.
              > > on server A I am getting a null pointer exception , which on tracing
              > happens to
              > > be the request dispatcher is null.(If http://www.abcz.com/<somepage> is
              > URL) but
              > > no null pointer exception if url is "/<somepage>"
              > > On B its behaving fine when given the "http://www.abcz.com/<somepage> " as
              > URL
              > > to the method.
              > > Both server A and B are running wl6. Is the difference in service pack
              > cause of
              > > the problem?
              > >
              > > Internally does wl6 parses the URL to find a relative URL?
              > >
              > > Any help will be greatly appreciated.
              > > Thanks
              > > Rumpa
              > >
              > >
              

  • Unable to use Request Dispatcher; Duke $ Post;

    I am using a Controller Servlet to transfer control to a JSP using Request Dispatcher within doPost()
    RequestDispatcher rd;
    rd=req.getRequestDispatcher(URL);
    rd.forward(req,resp);
    I am seting a request object
    req.setAttribute("XXX",obj.func());
    prior to the Redirect;
    The page gets redirected to a JSP. I am unable to access req object in there.
    if i use
    String XXX = req.getAttribute("XXX");
    i get an error in the jsp as
    "req cannot be resolved"
    Do i need to import some directives? Please Reply

    The page gets redirected to a JSP. I am unable to
    access req object in there.
    if i use
    String XXX = req.getAttribute("XXX");
    i get an error in the jsp as
    "req cannot be resolved"
    Do i need to import some directives? Please ReplyThat's simple. Your req (which is the HttpServletRequest object) in the servlet becomes request in the JSP. That's always there. The compiler would not recognize req
    Use request.getAttribute("XXX"); in JSP
    Regards
    ***Annie***

  • Looking to pass a "root" request to a WL server with Apache plugin

    Anyone know of a way to disclude a URL from the <Location> directive? I'm
    using the Apache plugin and would like to pass all requests through to the
    WL server except the images (which can be identified either by extension or
    by location (/images)). I want a request for http://apacheserver/ to get
    passed to the WL server and execute some default servlet. However... if I
    use <Location /> to pass this through... everything else will get passed
    through, even my image requests.
    Any ideas?

    Thanks for the help.
    Two location directives:
    <Location /myApp> and
    <Location /myImages>
    would end up passing my images request through to WL, no?
    The way I have it set up now, I have one tag:
    <Location /myApp>
    which (obviously) passes the /myApp/* requests to WL. This is good...
    any other request such as /images/myimage.gif stays on the web server. The
    only problem is that
    the initial hit to the site (www.mycompany.com) does not get passed through
    and
    I need it to map to a servlet on the WL server, without disrupting the flow
    of a
    /images/* request.. I have no images on the WL server.
    Anyone know of a way to disclude a URL from the <Location> directive?I'm
    using the Apache plugin and would like to pass all requests through tothe
    WL server except the images (which can be identified either by extensionor
    by location (/images)). I want a request for http://apacheserver/ to
    get
    passed to the WL server and execute some default servlet. However... ifI
    use <Location /> to pass this through... everything else will get passed
    through, even my image requests.
    Have your application reside at /myApp and images in /myImages. Then two
    <Location> stanzas,
    one for /myApp and one for /myImages will do what you want. I have an
    open case with support
    where I wanted /myApp/myImages and /myApp to resolve in the order the
    <Location> directives
    were found in httpd.conf, in much the same way you can have / and
    /images with
    Apache handling /images and WLS handing / . The case is still open and
    the workaround is
    described in the first sentence of this paragraph :)

  • How to pass 2 different REQUEST in the URL

    Hi,
    I want to pass 2 different REQUEST value when I click the Edit link of the Report (Report/Form).
    I have give VALUE1 in the Request property of edit link, I want to give 2 REQUEST value something like
    VALUE1, VALUE2...
    http://xxxxxx/pls/apex/f?p=1111:1:10000000:VALUE1:NO:::
    (here I want to pass VALUE1 & VALUE2 both as Request)
    Help appreciated.
    thanks,
    deepak

    You can only have one REQUEST at a time.
    Not sure why you would want to have multiple requests-- possibly to trigger multiple process blocks? If so, you can set up a process to run against multiple request values, by using the condition type of "value of expressoin 1 is contained in colon-delimited list in expression 2", setting express 1 to "REQUEST" and setting expression 2 to "VALUE1:VALUE2".
    If that won't solve your issue, please give us more detail on why you would want to use multiple values for a request, and we may be able to suggest an alternate approach.

  • Request dispatcher between 2 servers

    dear sear:
    can i use request dispatcher to go from one servers to another whith the same session.
    thanks,
    hamdi.

    Nope, Request dispatcher works with in its servlet container.
    May be you can you Request.sendRedirect()..
    not sure.

Maybe you are looking for

  • Button URL Windows

    I would like to use a Flash CS4 button to navigate to another page on my web site that doesn't open a 2nd window. As an example, when the Action Script 3.0 (below) is embedded as an SWF file within the html, a new window opens in addtion to the paren

  • Doubt in Solution Manager Workflow

    Hi all I have created one workflow for support disk. I used BUS2000116 business object. Before that i created Z business object for BUS2000116. Bcos i need to include events and methods (Customization). So i created  ZB2000116. After that i selected

  • New user - how do i synch movies with the iphone

    hello i have just purchased an iphone and before this i had been creating movies as mp4 files to transfer, however whn i connect to itunes i am able to transfer the files from a purchased show that appear in Tv shows but the files that appear as movi

  • Use of PreparedStatement

    Hello friends, I need help in understanding how the PreparedStatement works. 1. When we first create the PreparedStatement, database parse the sql statement and create the efficient access plan. 2. Then database cache the sql and the access plan. 3.

  • Best setup to sync properly

    I need help in figuring out the best setup before I buy the 3GS (hopefully on the 9th of July...). What I want is to use my MacBook Pro as the computer that I connect my phone to for syncing. Also, I want the phone to sync with my MobileMe account, a