0

Here is my code to handle one url redirect but how do I implement two url redirects based on the user's url?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    import="com.example.common.config.RuntimeConfig" %>
    <html> 
    <head>
    <% 
  response.setHeader("Cache-Control","no-cache"); // HTTP 1.1
  response.setHeader("Pragma","no-cache"); //HTTP 1.0
  response.setDateHeader("Expires", 0);
 %>
    </head>
    <body>
   <%
    String loginURL = RuntimeConfig
                        .getProperty("example.callback.url").asString();
    // if (request.getSession() != null)
    // {
 //     request.getSession().invalidate();
    // }
    //Take the user back to the login page
  response.sendRedirect(loginURL);
 %>
 </body>
 </html>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
David
  • 11
  • 3

1 Answers1

1

You can obtain the current request URI (the part after the domain name) by HttpServletRequest#getRequestURI()

String uri = request.getRequestURI();

You can compare a String with another String using java.lang.String methods like equals(), contains(), startsWith(), endsWith(), etcetera.

boolean equal = uri.equals("/expectedurl");

You can control the flow in Java code conditionally using if-else statements.

if (someCondition) {
    // Do something.
} else {
    // Do something else.
}

Do the math.


That said, this job should be done in a Filter rather than a JSP file.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555