How to get domain URL and application name?

Take a look at the documentation for HttpServletRequest. In order to build the URL in your example you will need to use: getScheme() getServerName() getServerPort() getContextPath() Here is a method that will return your example: public static String getURLWithContextPath(HttpServletRequest request) { return request.getScheme() + “://” + request.getServerName() + “:” + request.getServerPort() + request.getContextPath(); }

Prevent user from seeing previously visited secured page after logout

You can and should not disable the browser back button or history. That’s bad for user experience. There are JavaScript hacks, but they are not reliable and will also not work when the client has JS disabled. Your concrete problem is that the requested page is been loaded from the browser cache instead of straight … Read more

How to reference constants in EL?

EL 3.0 or newer If you’re already on Java EE 7 / EL 3.0, then the @page import will also import class constants in EL scope. <%@ page import=”com.example.YourConstants” %> This will under the covers be imported via ImportHandler#importClass() and be available as ${YourConstants.FOO}. Note that all java.lang.* classes are already implicitly imported and available … Read more

Strip whitespace from jsp output

There is a trimWhiteSpaces directive that should accomplish this, In your JSP: <%@ page trimDirectiveWhitespaces=”true” %> Or in the jsp-config section your web.xml (Note that this works starting from servlet specification 2.5.): <jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <trim-directive-whitespaces>true</trim-directive-whitespaces> </jsp-property-group> </jsp-config> Unfortunately if you have a required space it might also need strip that, so you may need … Read more

How to differ sessions in browser-tabs?

You can use HTML5 SessionStorage (window.sessionStorage). You will generate a random id and save in session Storage per Browser Tab. Then each browser tab has his own Id. Data stored using sessionStorage do not persist across browser tabs, even if two tabs both contain webpages from the same domain origin. In other words, data inside … Read more

How comment a JSP expression?

Pure JSP comments look like this: <%– Comment –%> So if you want to retain the “=“.you could do something like: <%–= map.size() –%> The key thing is that <%= defines the beginning of an expression, in which you can’t leave the body empty, but you could do something like this instead if the pure … Read more