0

我有不同的俱乐部,不同的领域如下:

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

问题场景:如果用户尝试订阅儿童俱乐部,如果他没有注册到这个俱乐部,他会被转发到域“kidclub.google.mobi”。但如果他已经注册,那么他应该被重定向到设置中定义的另一个俱乐部青年俱乐部 (youthclub.yahoo.mobi)。如果他再次注册到青年俱乐部,那么他应该会自动重定向到成人俱乐部(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 );
}
4

2 回答 2

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);
  }
于 2012-11-12T15:56:57.670 回答
0

我使用while循环来解决这个问题,它解决了!!

while(registered==true){

   //code for redirectconditions
    .......................

    checkifRegistered==false??
     }
  redirectUser(club URLLink);

谢谢,

于 2012-12-06T12:15:10.887 回答