

JSP Redirection Issue according to Condition
source link: https://www.codesd.com/item/jsp-redirection-issue-according-to-condition.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

JSP Redirection Issue according to Condition
I have different clubs with different domains as below :
Kid club = kidclub.google.mobi
Youth Club = youthclub.yahoo.mobi
Adult Club=adult.godaddy.mobi
Elderly Club = elderly.google.mobi
Redirection Settings are as below (sample redirection settings):
1. Kid Club should redirect to Youth Club
2. Youth Club should redirect to Adult Club
3. Adult Club should redirect to Elderly Club
4. Elderly Club should redirect to Kid club
Problem Scenario: If user tries to subscribe Kid Club then, if he is not registered to this club, he is forwarded to domain "kidclub.google.mobi". But if he is already registered then he should be redirected to another club Youth Club (youthclub.yahoo.mobi) AS defined in the settings. And if he is again already registered to Youth Club then he should be automatically redirected to Adult Club (adult.godaddy.mobi). This goes on until to the club he is not registered with.
I have the following code which just can redirect to a single club but I am not able to check the condition if the user is subscribed to second club or not.
//ClubDao.isActive(user,club) returns TRUE if user is active to that club and
FALSE if user is inactive.
if( user != null && club != null && ClubDao.isActive(user, club))
{
redirectReturningUser( request, response,domain );
}
void redirectReturningUser( HttpServletRequest request, HttpServletResponse
response,Domain currentDomain )
{
String redirectToUrl = currentDomain.getDefaultUrl();
if( "kidclub.google.mobi".equals( currentDomain.getDefaultUrl() ) )
redirectToUrl = "youthclub.yahoo.mobi";
else if( "youthclub.yahoo.mobi".equals( currentDomain.getDefaultUrl() ) )
redirectToUrl = "adult.godaddy.mobi";
else if( "adult.godaddy.mobi".equals( currentDomain.getDefaultUrl() ) )
redirectToUrl = "elderly.google.mobi";
else if( "elderly.google.mobi".equals( currentDomain.getDefaultUrl() ) )
redirectToUrl = "kidclub.google.mobi";
doRedirect(response, "http://"+redirectToUrl );
}
What if you map each Club
to the url string and then retrieve the string when the user membership against the club is established.
static Map<Club, String> redirectMap= new LinkedHashMap<Club, String>();
static {
redirectMap.put(new Club("kidclub.google.mobi"), "youthclub.yahoo.mobi");
redirectMap.put(new Club("youthclub.yahoo.mobi"), "adult.godaddy.mobi");
redirectMap.put(new Club("adult.godaddy.mobi"), "elderly.google.mobi");
redirectMap.put(new Club("elderly.google.mobi"), "kidclub.google.mobi");
}
void redirectReturningUser (HttpServletRequest request, HttpServletResponse response) throws IOException {
Map<Club, String> tmpRredirectMap = new LinkedHashMap<Club, String>();
for (Map.Entry<Club, String> entry: redirectMap.entrySet()){
Club club = entry.getKey();
String redirectUrl = entry.getValue();
if( user != null && club != null && ClubDao.isActive(user, club)) {
tmpRredirectMap.put(club, redirectUrl);
}
}
boolean done = false;
String tempUrl = domain.getDefaultUrl();
int count = redirectMap.size();
Club tempClub = new Club(tempUrl);
do {
if (tmpRredirectMap.keySet().contains(tempClub)){
tempClub = new Club(redirectMap.get(tempClub));
count--;
} else {
done = true;
}
} while (! done && count > 0);
redirectReturningUser(request, response, tempClub.getName());
}
void redirectReturningUser( HttpServletRequest request, HttpServletResponse response, String redirectUrl ) throws IOException {
doRedirect(response, "http://"+redirectUrl );
}
private void doRedirect(HttpServletResponse response, String s) throws IOException {
response.sendRedirect(s);
}
Recommend
-
17
Efficient Java Matrix Library
-
10
java-version.com: What's new in Java 16? 15? Keep up to date! How to solve the Angular redirection error (404) using Java
-
8
Automatic redirection on mobile breaks UXotsukare Thoughts after a day of workThis is another interesting case I have been dealing with today. When you try to access the Web site with...
-
15
HTTP redirection is hardotsukare Thoughts after a day of workHTTP redirection is hard Lun 24 octo...
-
13
Connect to Azure Database for MariaDB with redirection 06/08/2020 4 minutes to read In this article This topic explains how to connect an application y...
-
9
Serverless redirection to save us from ugly URLsI’m a fan of CI-independent serverless nuget feeds: you can push packages from arbitrary systems to a single feed that is high...
-
11
Redirection to the canonical path without slash in Rails 3 advertisements On Rails 3, I'm trying to redirect from a URL without a trailing slash to...
-
10
[译] 利用 ebpf redirection 提升 socket 性能(2020) Published at 2021-01-28 | Last Update 2021-01-28 译者序 本文翻译自 2020 年的一篇英文博客 How to use eBPF for accelerating Cloud Native applications。 原文...
-
14
本文翻译自 2020 年的一篇英文博客《 How to use eBPF for accelerating Cloud Native applications 》。 原文标题非常宽泛,但内容其实很技术:展示了...
-
6
[译] 利用 ebpf sockmap/redirection 提升 socket 性能(2020) Published at 2021-01-28 | Last Update 2021-01-28 本文翻译自 2020 年的一篇英文博客
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK