Search code examples
javaservletszk

Replace DesktopScope.put() and DesktopScope.put() in servlet


There are my project that are use 2 methods of the zk framework

DesktopScope.put() and DesktopScope.put()

and now i am removing zk. there are from wchi methods i can replace this method in servlet file

desktopScope.put("USER_NAME", userNameVal);
desktopScope.put(Constants.USER_DIR, userDirectory);

Solution

  • According to this page in the ZK documentation, the desktopScope object is a Map maintained by the ZK framework that holds variables shared at a particular scoping level; i.e. the desktop level.

    Now I can't figure out what the "wchi" framework is ... or whether that is just a typo. But if you are simply converting your code to plain JSP / JSTL code, then you need to figure out an appropriate JSP / JSTL scope (the standard ones are "page", "session", "request" and "application") and then set your variable from Java, depending on the scope:

    • "request" scope variables are set using Request.setAttribute
    • "session" scope variables are set using Session.setAttribute
    • "application" scope variables are setting ServletContext.setAttribute
    • "page" scope variables cannot be set outside of the page JSP.

    Note that the "desktop" scope is a purely ZK concept, and you are going to need to figure out a non-ZK way of achieving .... whatever it is that those variables achieve. The "session" scope might be the most appropriate.