Index: modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/AddPasswordServlet.java
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/AddPasswordServlet.java	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/AddPasswordServlet.java	(revision 51139)
@@ -2,6 +2,7 @@
 
 import eu.dnetlib.openaire.user.utils.LDAPActions;
 import eu.dnetlib.openaire.user.utils.VerificationActions;
+import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@@ -51,12 +52,14 @@
                 logger.info("password added");
             } catch (Exception e) {
                 logger.error("LDAP error in adding password", e);
-                response.sendRedirect("./error.jsp");
+                response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
+                //response.sendRedirect("./error.jsp");
             }
         }
 
         session.removeAttribute("username");
-        response.sendRedirect("./success.jsp");
+        response.sendRedirect(UrlConstructor.getRedirectUrl(request, "success.jsp"));
+        //response.sendRedirect("./success.jsp");
         printWriter.close();
 
     }
Index: modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/UrlConstructor.java
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/UrlConstructor.java	(nonexistent)
+++ modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/utils/UrlConstructor.java	(revision 51139)
@@ -0,0 +1,42 @@
+package eu.dnetlib.openaire.usermanagement.utils;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * Created by sofia on 8/3/2018.
+ */
+public class UrlConstructor {
+
+    public static String getRedirectUrl(HttpServletRequest request, String jspPage) {
+
+        String scheme = request.getScheme();
+        String serverName = request.getServerName();
+        int portNumber = request.getServerPort();
+        String contextPath = request.getContextPath();
+
+        String resultPath;
+        if (portNumber == 80) {
+            resultPath = scheme + "://" + serverName + contextPath + "/" + jspPage;
+        } else {
+            resultPath = scheme + "://" + serverName + ":" + portNumber + contextPath + "/" + jspPage;
+        }
+
+        if (jspPage.equals("error.jsp")) {
+            request.getSession().setAttribute("error", "true");
+        }
+        if (jspPage.equals("success.jsp")) {
+            request.getSession().setAttribute("success", "true");
+        }
+        if (jspPage.equals("successAddPassword.jsp")) {
+            request.getSession().setAttribute("successAddPassword", "true");
+        }
+        if (jspPage.equals("expiredVerificationCode.jsp")) {
+            request.getSession().setAttribute("expiredVerificationCode", "true");
+        }
+        if (jspPage.equals("registerSuccess.jsp")) {
+            request.getSession().setAttribute("registerSuccess", "true");
+        }
+
+        return resultPath;
+    }
+}
Index: modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ActivationCodeServlet.java
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ActivationCodeServlet.java	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ActivationCodeServlet.java	(revision 51139)
@@ -2,6 +2,7 @@
 
 import eu.dnetlib.openaire.user.utils.LDAPActions;
 import eu.dnetlib.openaire.user.utils.VerificationActions;
+import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@@ -51,12 +52,15 @@
                     ldapActions.moveUser(formUsername);
                 } catch (Exception e) {
                     logger.error("LDAP error in moving user", e);
-                    response.sendRedirect("./error.jsp");
+                    response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
+                    //response.sendRedirect("./error.jsp");
                 }
-                response.sendRedirect("./registerSuccess.jsp");
+                response.sendRedirect(UrlConstructor.getRedirectUrl(request, "registerSuccess.jsp"));
+                //response.sendRedirect("./registerSuccess.jsp");
             } else {
                 logger.info("Verification code has expired!");
-                response.sendRedirect("./expiredVerificationCode.jsp");
+                response.sendRedirect(UrlConstructor.getRedirectUrl(request, "expiredVerificationCode.jsp"));
+                //response.sendRedirect("./expiredVerificationCode.jsp");
             }
         } else {
             request.getSession().setAttribute("message", "Username or activation code are not valid.");
Index: modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/VerificationCodeServlet.java
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/VerificationCodeServlet.java	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/VerificationCodeServlet.java	(revision 51139)
@@ -1,6 +1,7 @@
 package eu.dnetlib.openaire.usermanagement;
 
 import eu.dnetlib.openaire.user.utils.VerificationActions;
+import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@@ -46,7 +47,8 @@
                 response.sendRedirect("./resetPassword.jsp");
             } else {
                 logger.info("Verification code has expired!");
-                response.sendRedirect("./expiredVerificationCode.jsp");
+                response.sendRedirect(UrlConstructor.getRedirectUrl(request, "expiredVerificationCode.jsp"));
+                //response.sendRedirect("./expiredVerificationCode.jsp");
             }
         } else {
             request.getSession().setAttribute("message", "Username or verification code are not valid.");
Index: modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RemindUsernameServlet.java
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RemindUsernameServlet.java	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RemindUsernameServlet.java	(revision 51139)
@@ -3,6 +3,7 @@
 import com.unboundid.ldap.sdk.LDAPException;
 import eu.dnetlib.openaire.user.utils.EmailSender;
 import eu.dnetlib.openaire.user.utils.LDAPActions;
+import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -67,11 +68,13 @@
 
         } catch (LDAPException ldape) {
             logger.error("Could not find user with email " + formEmail, ldape);
-            response.sendRedirect("./error.jsp");
+            response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
+            //response.sendRedirect("./error.jsp");
 
         } catch (MessagingException e) {
             logger.error("Error in sending email", e);
-            response.sendRedirect("./error.jsp");
+            response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
+            //response.sendRedirect("./error.jsp");
         }
 
     }
Index: modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java	(revision 51139)
@@ -4,12 +4,12 @@
 import eu.dnetlib.openaire.user.utils.EmailSender;
 import eu.dnetlib.openaire.user.utils.LDAPActions;
 import eu.dnetlib.openaire.user.utils.VerificationActions;
+import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
 
 import javax.mail.MessagingException;
-import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -72,18 +72,8 @@
                     verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
                 }
 
-                String scheme = request.getScheme();
-                String serverName = request.getServerName();
-                int portNumber = request.getServerPort();
-                String contextPath = request.getContextPath();
-                String resultPath;
+                String resultPath = UrlConstructor.getRedirectUrl(request, "verify.jsp");
 
-                if (portNumber == 80) {
-                    resultPath = scheme + "://" + serverName + contextPath + "/verify.jsp";
-                } else {
-                    resultPath = scheme + "://" + serverName + ":" + portNumber + contextPath + "/verify.jsp";
-                }
-
                 String verificationCodeMsg = "<p>Hello,</p>" +
                         "<p> A request has been made to reset your OpenAIRE account password. To reset your " +
                         "password, you will need to submit this verification code in order to verify that the " +
@@ -103,7 +93,8 @@
 
         } catch (LDAPException ldape) {
             logger.error("LDAP error", ldape);
-            response.sendRedirect("./error.jsp");
+            response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
+            //response.sendRedirect("./error.jsp");
 
         } catch (MessagingException e) {
             logger.error("Error in sending email", e);
@@ -113,4 +104,5 @@
 
     }
 
+
 }
Index: modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java	(revision 51139)
@@ -3,6 +3,7 @@
 import eu.dnetlib.openaire.user.utils.EmailSender;
 import eu.dnetlib.openaire.user.utils.LDAPActions;
 import eu.dnetlib.openaire.user.utils.VerificationActions;
+import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@@ -80,18 +81,8 @@
                          verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
                      }
 
-                     String scheme = request.getScheme();
-                     String serverName = request.getServerName();
-                     int portNumber = request.getServerPort();
-                     String contextPath = request.getContextPath();
-                     String resultPath;
+                     String resultPath = UrlConstructor.getRedirectUrl(request, "activate.jsp");
 
-                     if (portNumber == 80) {
-                         resultPath = scheme + "://" + serverName + contextPath + "/activate.jsp";
-                     } else {
-                         resultPath = scheme + "://" +serverName + ":" +portNumber + contextPath + "/activate.jsp";
-                     }
-
                      String verificationCodeMsg = "<p>Hello " + username + ",</p>" +
                              "<p> A request has been made to verify your email and activate your OpenAIRE account. To activate your " +
                              "account, you will need to submit your username and this activation code in order to verify that the" +
@@ -152,7 +143,8 @@
 
             } catch (Exception e) {
                 logger.error("LDAP error in creating user", e);
-                response.sendRedirect("./error.jsp");
+                response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
+                //response.sendRedirect("./error.jsp");
             }
         }
         printWriter.close();
Index: modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ResetPasswordServlet.java
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ResetPasswordServlet.java	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ResetPasswordServlet.java	(revision 51139)
@@ -2,6 +2,7 @@
 
 import eu.dnetlib.openaire.user.utils.LDAPActions;
 import eu.dnetlib.openaire.user.utils.VerificationActions;
+import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@@ -51,12 +52,14 @@
                 logger.info("password resetted");
             } catch (Exception e) {
                 logger.error("LDAP error in resetting password", e);
-                response.sendRedirect("./error.jsp");
+                response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
+                //response.sendRedirect("./error.jsp");
             }
         }
 
         session.removeAttribute("username");
-        response.sendRedirect("./success.jsp");
+        response.sendRedirect(UrlConstructor.getRedirectUrl(request, "success.jsp"));
+        //response.sendRedirect("./success.jsp");
         printWriter.close();
 
     }
Index: modules/dnet-openaire-users/trunk/src/main/webapp/error.jsp
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/webapp/error.jsp	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/webapp/error.jsp	(revision 51139)
@@ -7,6 +7,11 @@
 --%>
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <!DOCTYPE html>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
+<% if (session.getAttribute("error") == null) {
+    String redirectURL = request.getContextPath() + "/error404.jsp";
+    response.sendRedirect(redirectURL);
+}%>
 <html lang="en-gb" dir="ltr" vocab="http://schema.org/">
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Index: modules/dnet-openaire-users/trunk/src/main/webapp/expiredVerificationCode.jsp
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/webapp/expiredVerificationCode.jsp	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/webapp/expiredVerificationCode.jsp	(revision 51139)
@@ -7,6 +7,11 @@
 --%>
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <!DOCTYPE html>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
+<% if (session.getAttribute("expiredVerificationCode") == null) {
+    String redirectURL = request.getContextPath() + "/error404.jsp";
+    response.sendRedirect(redirectURL);
+}%>
 <html lang="en-gb" dir="ltr" vocab="http://schema.org/">
 <head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Index: modules/dnet-openaire-users/trunk/src/main/webapp/successAddPassword.jsp
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/webapp/successAddPassword.jsp	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/webapp/successAddPassword.jsp	(revision 51139)
@@ -9,6 +9,10 @@
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <!DOCTYPE html>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
+<% if (session.getAttribute("successAddPassword") == null) {
+    String redirectURL = request.getContextPath() + "/error404.jsp";
+    response.sendRedirect(redirectURL);
+}%>
 <META HTTP-EQUIV=Refresh CONTENT="0.5; URL=http://beta.services.openaire.eu/uoa-user-management/openid_connect_login">
 <html lang="en-gb" dir="ltr" vocab="http://schema.org/">
 <head>
Index: modules/dnet-openaire-users/trunk/src/main/webapp/resetPassword.jsp
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/webapp/resetPassword.jsp	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/webapp/resetPassword.jsp	(revision 51139)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <% if (session.getAttribute("username") == null) {
-  String redirectURL = "/dnet-openaire-users-1.0.0-SNAPSHOT/forgotPassword.jsp";
+  String redirectURL = request.getContextPath() + "/forgotPassword.jsp";
   response.sendRedirect(redirectURL);
   }
 %>
Index: modules/dnet-openaire-users/trunk/src/main/webapp/success.jsp
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/webapp/success.jsp	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/webapp/success.jsp	(revision 51139)
@@ -8,6 +8,10 @@
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <!DOCTYPE html>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
+<% if (session.getAttribute("success") == null) {
+    String redirectURL = request.getContextPath() + "/error404.jsp";
+    response.sendRedirect(redirectURL);
+}%>
 <META HTTP-EQUIV=Refresh CONTENT="0.5; URL=http://beta.services.openaire.eu/uoa-user-management/openid_connect_login">
 <html lang="en-gb" dir="ltr" vocab="http://schema.org/">
 <head>
Index: modules/dnet-openaire-users/trunk/src/main/webapp/addPassword.jsp
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/webapp/addPassword.jsp	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/webapp/addPassword.jsp	(revision 51139)
@@ -9,7 +9,7 @@
 <!DOCTYPE html>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <% if (session.getAttribute("username") == null) {
-    String redirectURL = "/dnet-openaire-users-1.0.0-SNAPSHOT/forgotPassword.jsp";
+    String redirectURL = request.getContextPath() + "/forgotPassword.jsp";
     response.sendRedirect(redirectURL);
 }%>
 <%--<%String name=(String)request.getAttribute("name");--%>
Index: modules/dnet-openaire-users/trunk/src/main/webapp/registerSuccess.jsp
===================================================================
--- modules/dnet-openaire-users/trunk/src/main/webapp/registerSuccess.jsp	(revision 51138)
+++ modules/dnet-openaire-users/trunk/src/main/webapp/registerSuccess.jsp	(revision 51139)
@@ -8,6 +8,10 @@
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 <!DOCTYPE html>
 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
+<% if (session.getAttribute("registerSuccess") == null) {
+    String redirectURL = request.getContextPath() + "/error404.jsp";
+    response.sendRedirect(redirectURL);
+}%>
 <META HTTP-EQUIV=Refresh CONTENT="0.5; URL=http://beta.services.openaire.eu/uoa-user-management/openid_connect_login">
 <html lang="en-gb" dir="ltr" vocab="http://schema.org/">
 <head>
