我有不同的俱乐部,不同的域名如下:
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 );
}发布于 2012-12-06 20:15:11
我使用while循环来解决这个问题,它成功了!
while(registered==true){
//code for redirectconditions
.......................
checkifRegistered==false??
}
redirectUser(club URLLink);谢谢,
发布于 2012-11-12 23:56:58
如果将每个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);
}https://stackoverflow.com/questions/13345864
复制相似问题