我有不同的俱乐部,如下所示:
Kid club = kidclub.google.mobi
Youth Club = youthclub.yahoo.mobi
Adult Club=adult.godaddy.mobi
Elderly Club = elderly.google.mobi
重定向设置如下(示例重定向设置):
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
问题场景: 如果用户尝试订阅Kid Club,那么如果他未在该俱乐部注册,则会转发到域名“kidclub.google.mobi”。但如果他已经注册,那么他应该被重定向到设置中定义的另一个俱乐部青年俱乐部(youthclub.yahoo.mobi)AS。如果他再次注册青年俱乐部,那么他应该被自动重定向到成人俱乐部(adult.godaddy.mobi)。这一直持续到他未注册的俱乐部。
我有以下代码可以重定向到一个俱乐部,但如果用户订阅了第二个俱乐部,我无法检查条件。
//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 );
}
答案 0 :(得分:0)
如果您将每个Club
映射到url字符串,然后在建立针对该俱乐部的用户成员资格时检索字符串,该怎么办。
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);
}
答案 1 :(得分:0)
我使用while循环来解决这个问题并且确定了!!
while(registered==true){
//code for redirectconditions
.......................
checkifRegistered==false??
}
redirectUser(club URLLink);
谢谢,