Question

I'm creating some pages for a web application, I currently have some pages with a brief description of a company and a link to allow them to log in to access more information. When the user logs in, they should be redirected to the more detailed version of the page.

In order to do this, when the user clicks on the log in link, I save the company name (as it is used in the url) to the session and access it when the user is logging in to figure out where to redirect them to.

This works fine but the only problem is these pages are using simple file name controllers and I don't want to implement controllers for them just so I can set this attribute. I've found a fix by using scriptlets in my jsp:

<a href="<c:url value='/login.jsp' />" 
      onclick="<% session.setAttribute( "partner", "companyName" ); %>" 
>
    Click here to log in
</a>

Now after some reading on SO and other resources I know that use of these scriptlets is highly discouraged, but I'm at a loss as to how to fix this problem without having to implement a controller to handle this simple problem. Any suggestions would be greatly appreciated.

Was it helpful?

Solution

use jstl

<c:set var="partner" value="companyName" scope="session" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top