13

In Tomcat Manager on the Page "Sessions Administration", there is a column Guessed User name. How can i set this column from within my Wicket Session?

Note: I have successfully overridden AuthenticatedWebSession.toString() and this value is shown on the sessin details page.

I have tried to set AuthenticatedWebSession.userName as recommended here.

Martin Schlagnitweit
  • 2,042
  • 6
  • 26
  • 42

2 Answers2

27

Please mind that Wicket session is a different beast than actual servlet session. Creating a "userName" property in wicket session will not work.

You need to access the raw HttpServletRequest from wicket to set the value properly: this is how you do it.

Add this code to your WebPages:

HttpServletRequest request = getWebRequestCycle().getWebRequest().getHttpServletRequest();
request.getSession().setAttribute("userName", userName);
Martin Schlagnitweit
  • 2,042
  • 6
  • 26
  • 42
lgawron
  • 522
  • 4
  • 8
  • 1
    There is also a column in Tomcat Manager Guessed Locale, maybe you know how to set it also? – zygimantus Sep 08 '15 at 06:38
  • @zygimantus, for locale, the manager tries the following attribute names: "org.apache.struts.action.LOCALE", "org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE", "javax.servlet.jsp.jstl.fmt.locale", "Locale", "java.util.Locale". See https://mail-archives.apache.org/mod_mbox/tomcat-users/200905.mbox/%3C0AAE5AB84B013E45A7B61CB66943C17228613EA2A8@USEA-EXCH7.na.uis.unisys.com%3E – Nikita Bosik Jan 20 '18 at 12:01
  • Is there any option to update Guessed Locale in apache server 9.0 – Phoenix Mar 06 '19 at 05:31
1

You can create any Java bean and add it to session like this, session.setAttribute("user", user); Tomcat will find the bean and whatever prints in toString will show up. see image here