tags:

views:

17

answers:

1

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>
+1  A: 

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.

BalusC
Thanks for your response. Does all of the code you suggested go into the filter class?
David