Announcement Announcement Module
Collapse
No announcement yet.
Possible to set a cookie from inside of surf? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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

      Comment


      • #4
        >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?

        Comment

        Working...
        X