Note that there are some explanatory texts on larger screens.

plurals
  1. PODetermine secure url in JSP with spring security
    primarykey
    data
    text
    <p>Like many websites, I have a login popup on every webpage of my site. Most of these pages are http (non-secure). But the login mechanism has to post to a secure url. All this works great. The problem is the secure url changes in the various dev environments, staging and different production environments.</p> <p>So not too big of a deal, I just have a properties file for each environment with the secure host and port. Now is there a way to encode the url with the right context and jsession id (if needed) and other things c:url normally does?</p> <p>for example:</p> <pre><code>&lt;form method="post" action="${rootHttpsUrl}/login"&gt; </code></pre> <p>I might think this would work to modify the url to add the right context, session info if needed, etc:</p> <pre><code>&lt;form method="post" action="&lt;c:url value='${rootHttpsUrl}/login'/&gt;"&gt; </code></pre> <p>But that doesn't work because c:url sees <a href="https://some-url.com" rel="nofollow noreferrer">https://some-url.com</a> and thinks it's an external link. So I could just modify the url myself:</p> <pre><code>&lt;form method="post" action="&lt;%=response.encodeURL(${rootHttpsUrl}${pageContext.request.contextPath}/login)%&gt;"&gt; </code></pre> <p>But escaping to java code like that doesn't let java see the rootHttpsUrl jsp variable (how do I expose this to java?). Is there a way to call encodeURL from within JSP?</p> <p>So what's the best solution here? I'm using Spring, Spring webmvc and Spring Security v3.0. Ideally there's something like</p> <pre><code>&lt;c:url value='/login' secure='true'/&gt; </code></pre> <p><strong>UPDATE</strong>: The best I've come up with is to have a properties file for each environment with a property for the https host and port. Then I add that to the model and reference any secure URL like this:</p> <pre><code>https://${httpsHostAndPort}&lt;c:url value='/login'/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload