Setting request attributes

If My JSP takes an attribute out of the request object that needs to be returned to the servlet, do I need to call setAttribute() with this value again or are the attributes in the request object automagically passed back to the servlet in the request object it receives?

A request attribute lasts the lifetime of a request.
A request starts when you push a button/link on the page (request an http page) and finishes when a response is returned to the browser.
Most time the jsp page is the final destination of a request (ie the object that sends the response). At this point all the attributes in request scope are lost.
You then have another page. Clicking a button/link on this page starts a new request with new parameters/attributes.
In order to keep java objects alive in-between requests, you need to use session attributes.
So to answer your question, no a JSP cannot return a page, and then pass an attribute to the servlet on the click of a button.
The only thing you can send along with a request from a page are request parameters.

Similar Messages

  • Set request attributes from the request attributes

    Using struts chaining actions.
    When using chaining the requestAttributes are lost.
    Is there a way to get all the request attributes and set them back to the request again?
    if so how to do this?
    Thanks.

    Looks like nobody knows :(
    It seems odd that nobody's tried to get InputSelectLOV or DataHandler working with a Struts app...
    ... anyway, on to finding out why the thing's throwing my releasemode away. This really is very like swimming through treacle :(

  • Setting request attribute

    In ServletRequest javadoc (2.5) the setAttribute(String,Object) has the following text:
    "If the object passed in is null, the effect is the same as calling removeAttribute(java.lang.String)."
    When doing a setAttribute with null value in OCCAS it throws a NPE.
    Is the SipServletRequest specified differently?
    /Henrik

    I see you mention OCCAS in your thread.
    But here is what javadoc says for sip servlets
    http://download.oracle.com/docs/cd/E13153_01/wlcp/wlss40/javadoc/jsr289/javax/servlet/sip/SipSession.html#setAttribute(java.lang.String,%20java.lang.Object)
    setAttribute
    void setAttribute(java.lang.String name,
    java.lang.Object attribute)
    Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.
    Parameters:
    name - the name to which the object is bound; cannot be null
    attribute - the object to be bound; cannot be null
    Throws:
    java.lang.IllegalStateException - if this method is called on an invalidated session
    java.lang.NullPointerException - on null name or attribute.
    So both name and value cannot be null

  • How to set the attributes of request in JSF Programming

    Hi All,
    for setting the attribute values for session, we do something like below.
    setValue("#{sessionScope.PREFERED_TOTALDAYS}",request.getParameter("txtDays")!=null?request.getParameter("txtDays"): ""+jobRowSet.getInt("PREFERED_TOTALDAYS"));
    Now my query is for setting the attribute values of request what is the code I need to use??
    thanks,
    sudhakar

    Just replace "sessionScope" with "requestScope". That will set the attribute request scope.
    Regards
    -Jayashri
    Creator team.

  • How to set session attributes in a bean?

    How do I set a session attribute in a server-side bean?
    I'm not sure if I asked the question the right way. What I meant is, while it's easy to set session attributes in a JSP page (session.setAttribute("sessionname", "sessionvalue")), I'd want to set such an attribute within a server-side bean defined in this web application. But what is the syntax for doing it?

    Here a simple bean that stores something in the session and retrieves something from it.
    import javax.servlet.http.HttpSession;
    public class TestBean {
      private String value;
      public void doSomething(HttpSession session, int a, int b) {
        if (a+b > 0) {
          session.setAttribute("ab",Boolean.TRUE);
        } else {
          session.setAttribute("ab",Boolean.FALSE);
      public void init(HttpSession session) {
        if (session != null) {
          Boolean b = (Boolean)session.getAttribute("ab");
          if (b == Boolean.TRUE) {
            value = "a + b is greater than zero";
          } else {
            value = "a + b is not greater than zero";
        } else {
          value = "no session";
      public String getValue() {
        return value;
    }In your JSP, use something along the lines of :
    <%
      TestBean bean = new TestBean();
      bean.init(session);
      bean.doSomething(session,1,2);
    %>If your bean only lives during one request, you can pass the session to the constructor, which stores it in a private variable. This saves passing the session each time.
    Hope this helps,
    --Arnout                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Javascript to JSP question...Can javascript function set session attributes

    hello,
    i have a web app that, on one of its pages, displays "tabbed pane" as an image map at the top (a la amazon.com). my problem is this: each "logical" page contains separate forms that all use the same javabean. in other words, imagine that the tabs represent an account maintenance web ui for an on-line record store. the first tab might be labeled "General," the second "Contact info," the third "Shipping Info." Each uses the same account bean and displays portions of its properties relevant to the tab at hand. what i want to do is allow a user to enter the account maintenance ui, update info on the first tab, click on tab two and have the request with the changes sent to a processing jsp. yet, since each "tab" is actually a separate URL to another page, how do i get the updated info on the first tabe without adding some sort of "SAVE" button on each tab. ive considered using javascript, but dont know how to get the request params out of the first tab whn i click on another tab. is it possible to include an "onClick" function in each URL that "grabs" the updated form fields off the preceeding tab? can a javacript function set session attributes in jsp?

    hello there,
    wow, you've created one big mammy-jammy tool.
    first, javascript cannot access, set values to the session, without having to post to another JSP. javascript is great for manipulating objects, layers, form values, etc.
    you have 2 issues [if i understand correctly]:
    1) you need to able to save user info for a specific tab without having to reloading the page.
    ---you can create a form for EACH of your tabs and POST all the information to a hidden IFRAME or LAYER for NN4. that hidden IFRAME / LAYER will load a JSP page which with all the parameters you posted to it. or you can build a FRAMESET and target that document["frame-name"].src with that same JSP.
    2) handling when the SAVE INFO action should happen: hence some javascript event handler: onMouseOver, onClick, etc
    ---i don't know the dynamics of your tabs, but if store which tab was clicked on last, then if the user clicks on some other tab, javascript can submit that FORM to a JSP [see condition above]
    you have an interesting tool. can i see?
    i hope i wasn't too confusing, but your problem is sooo interesting. =)
    -WJP

  • 'Requested attribute is invalid' error

    I'm attempting to programmatically get (and ultimately set) camera attributes with CVI. I can get some attribute values, such as ROI_WIDTH using the imgGetAttribute function, but not all, and not the ones that I really need to access, which are 'Exposure Time' and 'Gain Value'. I can see and set these exposure time and gain value camera attributes in MAX. However, when I attempt to use the imgGetCameraAttributeString function in IMAQ to get these attributes, I get the error 'The requested attribute in invalid'. My camera is the Basler acA2040-180km. In all other respects - snapping, grabbing, etc. the camera interface works fine.
    I cannot see what I am doing wrong or what piece I am missing, but it is obviously something. I took the NI example 'Analog attributes' as a starting point but that yields the same errors. How can MAX manipulate these camera attributes but I cannot in CVI? Is there some setup piece that is missing? 
    I'm kinda new to this environment, but would much appreciate any help anyone has.
    Thanks in advance,
    Wayne Showalter
    Solved!
    Go to Solution.

    Hi Wayne,
    IMAQ differerentiates in behavior and API with respect to 'IMAQ attributes' (defined by the IMAQ driver) and 'Camera Attributes' (defined by the camera file). All the ones with fixed constants (like ROI_WIDTH) are IMAQ attributes while the ones that specifically set something in the camera are camera attributes. You'll need to use the Get/SetCameraAttribute API for those. There are different functions for String vs Numeric attributes. I suspect if you call it with imgSetCameraAttributeNumeric() it will work.
    Eric

  • Use request attributes in JSF

    Is there a way we can pass data from one form bean to the other using request attributes insted of session attributes?
    I am able to work with session attributes using
    HttpSession mySession = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true); and setting attributes to it, but getting null pointers(occassionally) when I retrieve the atribute and work with it.
    getSession(false) isnt helping either.
    Looks like facesServlet is creating a new request when it forwards to next page. Any idea on how to get the Faces Servlet do something like request despatcher forward, for navigation so I can work with request attributes?
    Appreciate your input.

    Can I have just one backing bean and use it for all jsps in the app? App has 4 flows from home page and mutiple jsps in each flow. Each jsp has multiple form fields. Is that OK?
    Any way to passing data/objects between different backing beans - other than using session attributes? I had similar problems working on Struts app as well.

  • Is there a problem with too many request attributes

    I am fairly new to jsps and this is a best practices question
    I find that adding request attributes to my jsp is easy way to get data referenced in the jsp. Is this a bad practice and what is the ideal way to pass data to the jsp?
    Thanks.

    Putting attributes into the request scope if perfectly fine.
    If there are a lot of attributes though, grouping them into beans and just setting one bean in the request scope would be better.
    eg if you wanted to display a users details on screen, you COULD do
    request.setAttribute("username", user.getUserName());
    request.setAttribute("usercountry", user.getCountry());
    OR
    request.setAttribute("user", user);
    and on your JSP page
    <jsp:useBean id="user" ... />
    <%= user.getUserName() %>
    or with EL ${user.userName}
    Cheers,
    evnafets

  • Question re a branch's REQUEST attribute

    Can somebody explain to me the purpose of a branch's REQUEST attribute?
    When a button is pressed, its name is placed into the REQUEST application-level item. If it is a Submit button, processing will then take place and a branch that meets the conditions that are set will be run. So what is the point of having a REQUEST attribute in the branch itself? Thanks.

    For an example let's suppose you want to execute same PL-SQL block when submit or save buttons are pressed. If you write this on button pressed, you have to write two blocks of code, one to be executed after Submit and another for Save, whereas if you just assign a request after pressing a submit/Save button you can execute one single block based on the condition, "When Request contains- Save or Submit".
    --Manish                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Is deriving or check Change Request attributes in DERIVE_ENTITY or CHECK_ENTITY

    Hi,
    I'd have a requirement to derive or check  the Change Request attributes like Change Request Reason and Change Request Priority , e.g if CR Priority is empty, set to a specific value or Check if Change Request Reason is set.
    I know via an OSS message that we are not able to derive or check CR attributes using BRF+ but can we derive or check using the BADI?

    The BRF+ and BAdI solutions are directed more towards the master data entities. If you "only" want to default or check the CR header, then one idea is to enhance the CR Header handler class. Please see this document that describes how to enhance the CR Header. You don't need to add a field, but you can learn the technique of adding checks, etc. to the GenIL model handler class.
    Enhancement of the User Interface Building Bloc... | SCN

  • JSTL EL : Getting the type of all request attributes

    I want to loop thru all the request attributes and displaying their type or className. I wanna do that using jstl (no scriptlets).
    In the following code, what el expression shall is use for the value attribute of the c:out tag ?
    <c:forEach items="requestScope" var="currentAttribute">
    <c:out value="????"/>
    </c:forEach>

    Its a bit annoying, but I am curious as to howthis
    is important?not so much. i just didn't expect JSTL not to provide
    any way to achieve such a simple task.Yeah, things get complex when you try to make a unified approach of accessing things (the dot operator for both accessing properties through get/set methods, and for accessing values in a collection or array...). They had to choose one of the other for default behaviour I guess...
    If it really is, and you are using a JSP 2.0server,
    then maybe you can write up a utility function
    library that contains a Boolean instanceOf(Object
    obj, Class type) method, or String
    getClassName(Object) method...You mean a function like the jstl functions
    (startsWith, contains...)?Yeah. They aren't too hard, especially if you have any experience with custom tags (more importantly with TLDs and how to pack custom tags...)
    You just make a class with a bunch of public static methods. Then you create a TLD that defines the library name, URI, and what methods map where... You pack the class in a JAR, put the TLD in the META-INF directory and put the JAR inside your WEB-INF/lib directory. You access them just like you would the JSTL functions.

  • Return-to="currentPage" - Not able to get request attribute in page

    My JPF portlet has request "Request Attribute Persistence" as session.
    The Page Flow Refresh Action attribute is "refreshAction".
    My refreshAction annotation looks like this
    * This is called when the page is refreshed.
    * @jpf:action
    * @jpf:forward name="success" path="begin.do"
    * @jpf:forward name="goBackToCurrentPage" return-to="currentPage"
    * @jpf:forward name="goBackToPreviousPage" return-to="previousPage"
    * @jpf:forward name="goBackToPreviousAction" return-to="previousAction"
    When I try to forward to "goBackToCurrentPage", the request attribute that I had stored are not accessible in the JSP page.
    The only way for me to get that working is to change the forward to "goBackToPreviousAction".
    In this way, the action class will be called, which will inturn set the attribute in the request scope. However, this is a very expensive way.
    Is there something that I am missing here?

    Hi again!
    I must admit that I, after some tesing, had to leave the "goBackToPreviousAction" solution since it gave me some unwanted side effects.
    Instead I found a solution that actually works as one would expect.
    Thanks Graham Patterson!
    (http://forums.bea.com/bea/thread.jspa?messageID=200571206)
    My pfRefreshAction() now instead looks like this.
    * @jpf:action
    * @jpf:forward name="goBackToIndexPage" path="index.jsp"
    protected Forward pfRefreshAction()
    Forward forward = null;
    if ("forward to index page condition")
    forward = new Forward("goBackToIndexPage");
    return forward;
    Regards/ Thomas Lindbom :-)

  • Javax.servlet.forward.request_uri request attribute

    Hi,
    I have declared a security-constraint on my web application, which redirects to a page with a form.
    I want to know the initial request. It usually can be retrieved in the javax.servlet.forward.request_uri request attribute, so by doing
    request.getAttribute("javax.servlet.forward.request_uri")
    But this always returns me null.
    If I test the same thing on Tomcat, it works fine.
    This attribute come with Servlet 2.4, and Weblogic 11g is JEE 5 compliant (so Servlet 2.5). So it should work.
    Is there a particularity for Weblogic ?
    Regards

    >
    This attribute come with Servlet 2.4, and Weblogic 11g is JEE 5 compliant (so Servlet 2.5). So it should work.
    Is there a particularity for Weblogic ?This attribute does exist and has to be filled when a forward is done. However there's no strict requirement that the j_security_check is handled internally by a forward. If it's not, then that request attribute wouldn't come into play.
    I've never used it, so caveat emptor, but there is a public class we have which does appear to have some methods that may be helpful to you.
    http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e13941/weblogic/servlet/security/ServletAuthentication.html
    ServletAuthentication allows both form-based authentication and programmatic authentication in servlets. It performs the authentication call through the Realm and sets the user information into the session.And the static getTargetURLFromFormAuthentication method:
    http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e13941/weblogic/servlet/security/ServletAuthentication.html#getTargetURLForFormAuthentication(HttpSession)
    -steve-

  • Setting request parameters ?

    Hi there
    I tried the following:
    request.setAttribute("myVar", "myValue");
    pageContext.forward("/main");
    When it loads the main page, my variables are not being set.
    I have tried the <jsp:forward> page directive and this works for a simple test example I've used, but not when I try it in my application main page ( which consists of 3 frames). The 3 frames are all JSP pages, so does the time they get loaded affect the request and <jsp:forward> attributes being sent ?
    Or can I not just set request parameters?
    I'm stumped !
    Aaron

    No, thats not the case. getParameter and getAttribute return from different internal collections.
    An HttpServletRequest object will have two different HashMap objects (at least, they're probably HashMaps).
    One stores the parameters that were passed by the client's request (That's why they're always Strings - the client passes text using the HTTP GET and POST protocols). getParameter returns Strings from here.
    The other HashMap maintains objects that you add on the server side to pass between your servlets. You may want to add any type of object, so that's why these aren't required to be Strings.
    Think of neville's example (which allows you to use getParameter on the next page) as creating a new request that works as if the client had appended the extra parameters to the query string. You can't add non-String Objects using that method.
    If you try your simple example again using getAttribute, you'll probably find that it works.

Maybe you are looking for

  • Looking for a contract actionscript developer

    San Francisco Based Contract Actionscript -  Flex Developer | Streaming Video Solution We are currently seeking a full or part time (at least for the next several months) senior Actionscript & Flex contract developer to help establish our online stre

  • Addresse already in use

    Hi Folks, I am getting following exception when redeploying my server socket code. java.net.bindexception.address already in use. I know above error is bcos of port. but i am trying to close in finally block. when i do some other changes and try to r

  • How do I change font colour permanently in Mail.

    Can someone tell me how to permanently change the font colour in Mac Mail.  I have changed it from black to blue in preferences and also when I bring up the new message screen have changed to blue there also, but it still types out in black.  So I wo

  • Upgrade from RH6 to RH8

    Hello RH Experts, I need advice for buying the latest version of RH8. Our company upgraded from RH3 to RH6 in 2007. Now my boss wants me to find out about RH8. He is looking for two things - Context Sensitive Capability and Self Authoring capability.

  • REFRESH-CONTROL

    Hi, I have one screen with two tabstrips, one of them contains a chart and the other an ALV. If I leave the screen from the chart-tab and call it again, everything is ok. But when I leave it while ALV-Tab is active and call it again, the alv shows th