Results 1 to 4 of 4

Thread: Possible to set a cookie from inside of surf?

  1. #1
    Join Date
    Aug 2010
    Posts
    5

    Default Possible to set a cookie from inside of surf?

    Hey everyone!

    Quick, stupid question Is there any way to set a cookie from inside of a SURF-based app? (from either a java or javascript-backed bean? )

    I've found the FrameworkUtil and ServletUtil classes, from which I can access the current HttpServletRequest object, but can't find access to the HttpServletResponse object to set the cookie..

    Thanks!
    jim

  2. #2

    Default

    Hi,

    From a URL executed Java backed WebScript you can access the HttpServletRequest and HttpServletResponse to get/set Cookies etc. thus:

    Code:
        public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
        {
            HttpServletRequest httpReq = ((WebScriptServletRequest)req).getHttpServletRequest();
            HttpServletResponse httpRes = ((WebScriptServletResponse)res).getHttpServletResponse();
            ...
        }
    From within a Surf component WebScript you are more limited in that you are running as part of a full page execution - i.e. you cannot directly write to the response header as part of it may already have been committed - such as Cookies etc. and any number of components previously to yours, so you can only access the HttpServletRequest as that is safe to do so.

    Cheers,

    Kev

  3. #3
    Join Date
    Aug 2010
    Posts
    5

    Default Nice!

    Thanks Kevin!

    Lol I guess I should have checked the most obvious place first I've actually only been using DeclarativeWebScripts so far..

    Is there a recommened/preferred way to return a page from the SURF page flow at the end of an AbstractWebScript? (other than just a sendRedirect?)

    Thanks again for all your help!
    jim

  4. #4

    Default

    >Is there a recommened/preferred way to return a page from the SURF page flow at the end of an AbstractWebScript? (other than just a sendRedirect?)

    Not sure what you would expect to do? Do you mean from a component webscript or a Java backed URL executed webscript?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •