Forwarding from java servlet to jsp file

48 views
Skip to first unread message

JJ Fila

unread,
Sep 17, 2018, 3:27:33 PM9/17/18
to uPortal Community
Hey Everyone,

Working with Google SSO, and am trying to do something similar to this in a java servlet:

String returnPage = "./gmailSamlResponse.jsp";

request.getRequestDispatcher(returnPage).include(request, response);


However, the way uPortal works is these jsp files are accessible through only portlets correct? Assuming that, I set up a google response SimpleJSP Portlet, and the jsp file is located here: uportal-portlets-overlay/jasig-widget-portlets/src/main/webapp/WEB-INF/jsp/googleSamlResponse.jsp

However, I'm not sure how to use the Request Dispatcher to redirect to that page? I tried getting the portlet url using a IPortalUrlBuilder, and essentially did this (hard coded return page for simplicity):

String returnPage = "/normal/render.uP?pCt=google-saml-response-portlet.ctf3";

request.getRequestDispatcher(returnPage).include(request, response);


But this didn't work either.

Does anyone know how I might use the dispatcher to my gmailSamlResponse.jsp file?

Thanks!
JJ

Andrew Petro

unread,
Sep 19, 2018, 10:34:42 AM9/19/18
to uPortal Community
Everything doesn't have to be a Portlet. Portlet web applications can also be Servlet web applications and have Servlets, and indeed uPortal itself has Servlets.

JJ Fila

unread,
Oct 1, 2018, 10:07:42 AM10/1/18
to uPortal Community
Andrew,

Thanks for the reply. Thanks makes sense (I think? Still learning). The reason I wanted to use the jsp file is because our previous version of the Google SSO integration sent a post back through an HTML form tag like this:

     <form action="<%=acsURL%>" method="post">

       <div style="display: none">

         <textarea rows=10 cols=80 name="SAMLResponse"><%=samlResponse%></textarea>

         <textarea rows=10 cols=80 name="RelayState"><%=RequestUtil.htmlEncode(relayState)%></textarea>

       </div>

     </form>


And I am not sure how to replicate this behavior in a java file? I do have a servlet running, but it only lets me use a java file, not jsp - correct?

JJ Fila

unread,
Oct 16, 2018, 10:56:22 AM10/16/18
to uPortal Community
Hey guys,

Just wanted to post an update: I was able to send the POST request via the java servlet itself, so I was able to move past this. Thanks!

JJ Fila

unread,
Oct 25, 2018, 10:38:31 AM10/25/18
to uPortal Community
I'm finding it may still be helpful to forward to a jsp file. However, the only way I know how is to show one through a portlet. But, the problem I am having is the httpSession changes when I do this and so I lose my session variables. 

Does anyone know how I might forward from a servlet (say https://portal.domain.edu/uPortal/ProcessResponseServlet) to a jsp file (say https://portal.domain.edu/uPortal/jspFile.jsp)? Or alternatively, does anyone know how to stay within the same httpSession when redirecting to a portlet?

- JJ

JJ Fila

unread,
Oct 25, 2018, 2:22:09 PM10/25/18
to uPortal Community
Quick update:

I was able to get this working by directly printing the html I got back from Google like so:

PrintWriter out = response.getWriter();

out.println(responseBuf.toString());


This is deprecated, however, so I am still curious if there might be a way to forward this text to a jsp file to display it.

- JJ
Reply all
Reply to author
Forward
0 new messages