Purpose of request.setAttribute(String parm1, Object parm2)

HttpServletRequest request.setAttribute(String parm1, Object parm2) vs. HttpSession session.setAttribute(String parm1, Object parm2)
hi
can anybody please explain to me what does HttpServletRequest request.setAttribute() do? and for what purpose is it used for?
i already know that HttpSession session.setAttribute(String parm1, Object parm2) is used to bind a session to a variable, so that it can be accessed throughout the servlet application.
thanx
shankha
ps: please correct me if i'm wrong

shankha,
What does the API doco say?
I think it just sets a request scoped attribute... ie a request parameter.
This looks pertinant: http://www.rgagnon.com/javadetails/java-0401.html

Similar Messages

  • SetAttribute(String, Object) error

    Hello Guys,
    I have in my jsp page something like this.
    request.setAttribute("variable",0). When i load the page, it comes with an error saying that
    Generated servlet error:
    The method setAttribute(String, Object) in the type HttpSession is not applicable for the arguments (String, int)
    I tried various things like
    Integer v = new Integer(0);
    Integer.valueOf(0).
    But it comes up with the same error.
    Any ideas?
    Help would be appreciated.
    Kay

    The method setAttribute(String, Object) in the type HttpSession is not applicable for the arguments (String, int)This says it all. setAttribute() doesn't work for primitives, it only takes Objects. So you have to use an Integer and not an int. A String will work fine too.

  • Request.setAttribute with strings that hold URLs

    Hi,
    In my servlet I do request.setAttribute(stringKey,stringValue) and then dispatch to a jsp. In that jsp I use the attributes with value = request.getparameter(stringKey) and value I use in <c:import> tags.
    This value is a string that holds complete URLs!
    Now upon doing this I get ArrayIndexOutOfBoundsException. How to solve this?
    Hope someone can explain me what's wrong and what possible solution there is.
    Greets,
    Timv
    java.lang.ArrayIndexOutOfBoundsException: 20
         at org.apache.catalina.util.RequestUtil.URLDecode(RequestUtil.java:465)
         at org.apache.catalina.util.RequestUtil.URLDecode(RequestUtil.java:427)
         at org.apache.catalina.util.RequestUtil.URLDecode(RequestUtil.java:391)
         at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:615)
         at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:174)
         at org.apache.taglibs.standard.tag.common.core.ImportSupport.acquireString(ImportSupport.java:302)
         at org.apache.taglibs.standard.tag.common.core.ImportSupport.doEndTag(ImportSupport.java:179)
         at jasper.disclaimer_jsp._jspService(_disclaimer_jsp.java:131)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:552)
         at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:368)
         at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:287)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:720)
         at org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrapperValve.java:118)
         at org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperValve.java:278)
         at java.security.AccessController.doPrivileged(Native Method)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:274)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:203)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:505)
         at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:158)
         at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)

    Ok, sorry, I was too fast..
    I was using rtexpr (<%=parameter%>) instead of ${parameter}",
    greets

  • How to use request.setAttribute in javascript function.

    Here is my scenario.
    I am storing all open windows handles in the array( javascript ).
    I want to send this array to the servlet for which I need to do
    request.setAttribute("jsArray", windowArray);
    I am getting all kinds of errors while writing above statement in the javascript function.
    Here is my code:
    function save_javascript_array(){
    <% request.setAttribute("jsArray", %> + winArray + <% ); %>
    document.forms[0].action="/NASApp/inv/AuditServlet";
    document.forms[0].submit();
    Thanks in advance.

    try something like this:
    crate a JavaScript function that set a form parameter with the values contained in the array, for example make a string containing all elements of the array separated by colon (,):
    function save_javascript_array()
    var data;
    data = '';
    for( var i=0;i<winArray.length;i++ )
    data = data + winArray[i] + ',';
    document.forms[0].handles.value = data;
    document.forms[0].action="/NASApp/inv/AuditServlet";
    document.forms[0].submit();
    you must have a form like this:
    <form ...>
    <input type="hidden" name="handles">
    </form>
    Now in the servlet you must retirve the parameter called "handles" and iterate over the string:
    StringTokenizer tok = new StringTokenizer( request.getParameter("handles"),"," );
    while( tok.hasMoreElements() )
    String handle = tok.nextToken( );
    // do something with this handle...
    The code above may be different (I don't remember the names of the methods os StringTokenizer) and I don't known much about JavaScript (e.i. how to iterate over a array and how to concatenate each element in the array)
    JaimeS

  • Struts tag for request.setAttribute() in a jsp page

    Hello All
    Does anyone know struts tag that can be used for request.setAttribute() in a jsp page?
    Thanx in advance.

    Well
    <bean:define id="foo" name="newsIdAttribute" scope="request" type="java.lang.String" />is equivalent to
    <%
    (java.lang.String) foo = (java.lang.String)request.getAttribute("newsIdAttribute");
    %for setting bean properties you might have to use
    <jsp:setProperty/> or <c:set/> tags in JSP / JSTL respectively.
    Hope this might answer your question :)
    REGARDS,
    RaHuL

  • Request.setAttribute between classes

    Hi I'm trying to keep a userid from a class call ActionLogin to then use it to select products bought by that user
    request.setAttribute("userid", login);Then I realize that userid isn't keeping anything when I'm tryin got access it with
    request.getParameter("userid") or
    request.getAttribute("userid") I just get a null string when I do this from another class or that same class.. am I supposed to use something else?

    Attributes which are set in the ServletRequest have a lifetime of one request. In your case, rather use session instead.
    And there is a certain difference between parameters and attributes.

  • How to get the request xml string in Business service.

    Hi
    I have following requirement
    1) XAI inbound service will get a input xml request feed and call the Business Service.
    2) Business service will do some validation and do the insert in the database.
    My BS schema is as below
    <schema pageAction="change">
    <personId mapField="PER_ID"/>
    <personOrBusiness mapField="PER_OR_BUS_FLG"/>
    <name mapField="ENTITY_NAME" mdField="C1_ENTITY_NAME"/>
    <emailAddress mapField="EMAILID"/>
    <city mapField="CITY"/>
    <county mapField="COUNTY"/>
    <postal mapField="POSTAL"/>
    <houseType mapField="HOUSE_TYPE"/>
    <taxVendorGeographicalCode mapField="GEO_CODE"/>
    <isInCityLimit mapField="IN_CITY_LIMIT"/>
    <state mapField="STATE"/>
    <version mapField="VERSION"/>
    <division mapField="CIS_DIVISION"/>
    <accessGroup mapField="ACCESS_GRP_CD"/>
    <address1 mapField="ADDRESS1"/>
    <personCharacteristic type="list" mapList="CI_PER_CHAR">
    <personId mapField="PER_ID"/>
    <characteristicType mapField="CHAR_TYPE_CD"/>
    <characteristicValue mapField="CHAR_VAL"/>
    <effectiveDate mapField="EFFDT"/>
    <adhocCharacteristicValue mapField="ADHOC_CHAR_VAL"/>
    <characteristicValueForeignKey1 mapField="CHAR_VAL_FK1"/>
    <characteristicValueFK2 mapField="CHAR_VAL_FK2"/>
    <characteristicValueFK3 mapField="CHAR_VAL_FK3"/>
    <characteristicValueFk4 mapField="CHAR_VAL_FK4"/>
    <characteristicValueFK5 mapField="CHAR_VAL_FK5"/>
    </personCharacteristic>
    </schema>
    The request XML to BS is as below_
    (support.schema.AbstractSchemaBasedDispatcher) Performing page:change of BusinessService CM_SPRDSHT_BS' (service='CMSPRDHSHTUPLD'), with input request
    <?xml version="1.0" encoding="UTF-8"?>
    <CM_Person>
    <personOrBusiness>P</personOrBusiness>
    <name>Marsh,Corporate</name>
    <emailAddress>[email protected]</emailAddress>
    <city>Tampa</city>
    <country>USA</country>
    <postal>2131</postal>
    <houseType/>
    <taxVendorGeographicalCode/>
    <isInCityLimit/>
    <state>CA</state>
    <version>1</version>
    <division>930</division>
    <accessGroup>***</accessGroup>
    <address1>Address of Khan</address1>
    </CM_Person>
    I can access the values of each xml node in BS with the help of data item.
    I wanted to know how can I get the above request xml string in my Business Service in Java.

    {color:#0000ff}http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#parseInt(java.lang.String)
    http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#valueOf(java.lang.String){color}

  • How does request.setAttribute() works?

    How does request.setAttribute() works?
              Does it append data to http header and forward? Does it set to a memory
              space like session.setAttribute() does?
              Thank you
              Jim
              

              Q. Does it append data to http header and forward?
              No.
              Q. Does it set to a memory space like session.setAttribute() does?
              Yes. So you can set attributes in request scope and use them in the servlets and
              JSPs in the servlet chain via request dispatcher and jsp:include/jsp:forward.
              "Jim" <[email protected]> wrote:
              >How does request.setAttribute() works?
              >Does it append data to http header and forward? Does it set to a memory
              >space like session.setAttribute() does?
              >
              >Thank you
              >Jim
              >
              >
              

  • Is there any limitation about request.setAttribute() ?

    I need to set a CLOB data to request.setAttribute() , just wonder if there any size limitation of putting data to setAttribute() and dispatch to other jsp to pick it up?

    Only the maximum amount of memory in the Servlet Container itself. The RequestDispatcher will always dispatch to the same JVM in a distributed environment, so the data doesn't need to be Serializable.
    Brian

  • Conver a string to object?

    hi, I am having problem converting string to object, then store the object into a object linklist node. I debugged it to make sure that everything the user types got stored in the string, but when the debug reaches "obj = temp;". obj doesn't have any value. why is that??
    String temp;
    Object obj;
    //have the user input something to the string. then...
    obj = temp;
    temp = (String) obj;
    ObjNode.insert(obj);
    Thank you...

    well, it's one of my assignment. have to write a class of object circular linked queue with a main funtion to test it. in the main function, I have to somehow store the object into the object node, but I havn't learned how to read object, only string. so I am tring to read string then change to object and store it. but if you could tell me how to just read object, it would be much easier for me.
    thank you.

  • String to object?

    Hi,
    I have a problem in converting string to object.
    The way I intended to do is like this:
    String a1 = "John";
    String a2 = "Smilth";
    String a3 = "Eric";
    String a10 = "Howard";
    and I wanna assgin the value of a1 ~ a10 into a temp string.
    like this;
    for (int i = 1; i<= 10; i++)
    String tempString = "a" + i; //assign the value of original string into tempString.
    // bla bla bla
    I know I have to use class.forName() to get what I want, but I have no clue on how to
    implement this in detail. Any help will be great appreciated.
    Thanks
    TC Wang

    May I ask why you do it so complicatec? Why don't you use an array?
    String[] a = new String[10]
    a[0] = "John";
    a[1] = "Smilth";
    a[2] = "Eric";
    a[9] = "Howard";
    // arrays start with zero, but 0 to 9 are also ten entries just
    // like 1 to 10.
    for (int j = 0; j <= a.length; j++)
        String tempString = a[j];
        // Here goes your other code
    // I replaced i with j, because i surrounded by round brackets
    // means printing text cursive on this BBS board

  • Delta Request deletion from info object

    Hi,
      We are loading 'DELTA's' for master data to an info object.
      Last night delta was failed due to idoc error.
      how can i delete the delta request from the info object and re do the delta again...
      I inserted the info object as data target so that i can get an option of manage on context menu...but when i did that there are no requests show in the manage of info object
    how can i delete failed data request from an info object and re do the delta  again
    Thanks

    Hi BW KING,
    An infoobject can be a data target and also use direct update. Are you loading using an InfoSource? Check where you have the load infopackage, if it's under an infosource, you can do that. If you have your infopackage under the infoobject "icon" (without update rules), then you don't have the option to manage the loads.
    Hope this helps.
    Regards,
    Diego

  • How can i write request.setAttribute/

    Hi,
    I have some data in a text box in jsp.
    I want to create session scope for that text box data
    like request.setAttribute
    How can I write request.setAttribute for a field in a jsp on that jsp itself.
    I using struts & JSTL.
    Advanced Thanks,
    Mahendra

    Use the javascript and create a session from JSP itself.

  • Newbie request.getParameter(String) issue

    I'm having an issue setting a boolean value in a bean based off a string from request.getParameter(). I've created a small example to illustrate what I want to happen:
    testForm.jsp:
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
        <title>testForm</title>
      </head>
      <body><form method="POST" action="testWork.jsp">
          <input type="hidden" name="hiddenTest" value="1"/>
          <input type="submit" name="submitTest" value="Submit"/>
        </form></body>
    </html>testWork.jsp:
    <jsp:useBean id="test" scope="session"
                 class="thistestapp.testClass"/>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
        <title>testWork</title>
      </head>
      <body>
      <%
      out.print("<p>" + request.getParameter("hiddenTest") + "</p>" );
      // Great it's sending "1"
      test.setTestB(request.getParameter("hiddenTest"));
      //So when I set this in the bean I should get true
      out.print("<p>" + test.getTestB() + "</p>" ); 
      //False? Not nice!!
      test.setTestB("1");
      //Alright there must be an issue with my code in the bean, so hardcode a
      //"1" in.  I should still get false.
      out.print("<p>" + test.getTestB() + "</p>" );
      //True?? I hate you.
      %>
      </body>
    </html>testClass.java:
    package thistestapp;
    public class testClass {
        private Boolean testB;
        public void setTestB(String testB) {
            if ( testB == "1"){
               this.testB = true;
            else{
               this.testB = false;
        public Boolean getTestB() {
            return testB;
    }So, I want when the bean is sent a "1" from the form to set the bean value to true. I however can't get that to happen. I'm sure there's something I'm missing.
    TIA.
    Joe

    ? if ( testB == "1"){
    Standard beginner's error. If you want to test if two strings contain the same text, use the equals() method. Like this:if ( testB.equals("1")){Your code tests whether the two sides of the == operator refer to the same object. It's possible and likely for two different strings to contain the same value, which is what you are really interested in.

  • Problems with String[] Class Object

    Hi guys,
    I'm writing a web server who should invoke a method of a class when asked by a client.
    My problem is that if the method that should be invoked has a String[] parameter the web server is unable to invoke it and throws a java.lang.IllegalArgumentException: argument type mismatch.
    Useful pieces of code to understand are the following:
    //create the Class[] to pass as parameter to the getMethod method
    Class[] paramType = {String[].class};
    //find the class "className" and create a new instance
    Class c = Class.forName(className);
    Object obj = c.newInstance();
    //the getMethod should find in the class c the method called nameMeth
    // having paramType (i.e. String[]) as parameter type...
    Method theMethod = c.getMethod(nameMeth, paramType);
    //here's the problematic call!!
    theMethod.invoke(obj, params);I've noted that System.out.println(theMethod); prints the signature of the method with the parameter type java.lang.String[].
    System.out.println(paramType[0]); instead prints [Ljava.lang.String;
    I know that [L means that it is an array, so why do you think that I'm having an argument type mismatch?
    Thank you                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I had no problems making that work.import java.lang.reflect.Method;
    public final class StringArray {
        public static final String CLASSNAME = "StringArray";
        public static final String METHODNAME = "myMethod";
        public static final String[] sa = { "a", "b"};
        // automatic no-args constructor
        public final void myMethod(String[] sa) {
            for(int i=0;i<sa.length;++i) {
                System.out.println(sa);
    public static final void main(String[] arg) throws Exception {
    //create the Class[] to pass as parameter to the getMethod method
    Object[] params = { sa };
    Class[] paramType = {sa.getClass()};
    //find the class "className" and create a new instance
    Class c = Class.forName(CLASSNAME);
    Object obj = c.newInstance();
    //the getMethod should find in the class c the method called nameMeth
    // having paramType (i.e. String[]) as parameter type...
    Method theMethod = c.getMethod(METHODNAME, paramType);
    //here's the problematic call!!
    theMethod.invoke(obj, params);

Maybe you are looking for

  • Image hyperlink not working in iphone mail

    Hello, I have created an HTML email and have sent it using Outlook from a Windows PC. The HTML email contains a JPEG that has a hyperlink assigned to it. When I check my email on my iphone and touch the JPEG, it wants to download the image, but does

  • Drillthrough using a cluster name

    Hi I'm looking to use a hyperlink  to open a BO report containing detailed business data from a summary report which gives a total count of records for each type of business data. This is from http://devlibrary.businessobjects.com " href="http://<web

  • UPDATE statment

    hi for all, plz i have a question ,i have a tabel called (ClientT) which contain these fielde First_Name Last_Name UserID Address Password BirthDate Answer and i need to make an Update to this table according to some informatio ,My Code Class.forName

  • Illustrator cs4 says memory full, images gone, please help

    is anyone awake?  It's almost 3 inthe morning and I'm in computer ****.  I might loose hours and hours of work.  anyone help with mac memory?

  • Send IDoc through adapter IDoc_AAE

    Hi, guys! We have SAP PO version 7.4 We need to setup the unloading of the IDoc from BI in PO I used the following sources: http://scn.sap.com/docs/DOC-31398  http://help.sap.com/saphelp_nw74/helpdata/en/34/66c81241874285851e2497aa6f0573/content.htm?