开发者

How do I include another login page and direct the user to one of the two login pages based on his url?

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> 
    <h开发者_如何学Cead>
    <% 
  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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜