No session creation throws DisabledSessionException when servlet dispatcher forwards to jsp page

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

No session creation throws DisabledSessionException when servlet dispatcher forwards to jsp page

armandoxxx
This post was updated on .
Hi guys

I've implemented some preview image service which should not have shiro
session but I use shiro for login per request.

Service servlet resolves, depending on user, what images should be displayed
and then sets context values for JSP to display.
Since I use noSessionCreation filter for my servelet uri, I get
DisabledSessionException when servlet dispatcher forwards to my jsp page.

Is there anything I can do to fix this problem?

String dispatchPath = "/html_template.jspx";
      RequestDispatcher dispatcher = request.getRequestDispatcher(dispatchPath);
      if (dispatcher != null) {
        try {
          dispatcher.forward(request, response);
        } catch (ServletException se) {
          throw new IOException(se);
        }
      } else {
        throw new IOException("Unable to load/forward to template [" + dispatchPath + "]");
      }

Any help appreciated

Regards

Armando



--
Sent from: http://shiro-user.582556.n2.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: No session creation throws DisabledSessionException when servlet dispatcher forwards to jsp page

armandoxxx
I have even tried configuration for jsp page ... not luck



Any help appreciated



--
Sent from: http://shiro-user.582556.n2.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: No session creation throws DisabledSessionException when servlet dispatcher forwards to jsp page

Brian Demers
Do you have a stack trace?  Is your servlet accessing the session?  Do you have a snippet of how your servlet is doing the forwarding?

On Wed, Mar 4, 2020 at 5:13 AM armandoxxx <[hidden email]> wrote:
I have even tried configuration for jsp page ... not luck



Any help appreciated



--
Sent from: http://shiro-user.582556.n2.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: No session creation throws DisabledSessionException when servlet dispatcher forwards to jsp page

armandoxxx
I figured it out .. .

My use case is that users can request some HTML page, but I don't want to
have session open for them. No need for sessions in this case.  So when you
call dispatcher.forward ( ... ) in servlet, your request is forwarded to JSP
page and shiro process (Subject.getSessio()...) and checks  are executed.
Dont use noSessionCreation when you use servlet - jsp combination since
servlet forwards request to your jsp. If you must, you should either write
html to servlet response (which is not a good practice) or use some template
framework (ie: freemarker template) to do this for you.
NoSessionCreation is meant for one time requst, response calls like rest or
soap as stated in docs.

Regards
Armando








--
Sent from: http://shiro-user.582556.n2.nabble.com/