Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 根据条件的JSP重定向问题_Java_Jsp - Fatal编程技术网

Java 根据条件的JSP重定向问题

Java 根据条件的JSP重定向问题,java,jsp,Java,Jsp,我有不同领域的不同俱乐部,如下所示: Kid club = kidclub.google.mobi Youth Club = youthclub.yahoo.mobi Adult Club=adult.godaddy.mobi Elderly Club = elderly.google.mobi 重定向设置如下(示例重定向设置): 问题场景: 若用户试图订阅Kid Club,若他并没有注册到该俱乐部,他将被转发到域名“kidclub.google.mobi”。但是如果他已经注册,那么他应该被重

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

Kid club = kidclub.google.mobi
Youth Club = youthclub.yahoo.mobi
Adult Club=adult.godaddy.mobi
Elderly Club = elderly.google.mobi
重定向设置如下(示例重定向设置):

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

如果您将每个
俱乐部
映射到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);
  }
staticmap redirectMap=newlinkedhashmap();
静止的{
redirectMap.put(新俱乐部(“kidclub.google.mobi”)、“youthclub.yahoo.mobi”);
redirectMap.put(新俱乐部(“youthclub.yahoo.mobi”),“成人.godaddy.mobi”);
重定向map.put(新俱乐部(“成人.戈达迪.莫比”),“老年人.谷歌.莫比”);
重定向map.put(新俱乐部(“elder.google.mobi”),“kidclub.google.mobi”);
}
void redirectReturningUser(HttpServletRequest请求,HttpServletResponse响应)引发IOException{
Map tmpRredirectMap=新建LinkedHashMap();
对于(Map.Entry:redirectMap.entrySet()){
Club Club=entry.getKey();
字符串重定向URL=entry.getValue();
if(user!=null&&club!=null&&ClubDao.isActive(user,club)){
tmpRredirectMap.put(俱乐部,重定向URL);
}
}
布尔完成=假;
字符串tempUrl=domain.getDefaultUrl();
int count=redirectMap.size();
俱乐部tempClub=新俱乐部(tempUrl);
做{
if(tmpRredirectMap.keySet().contains(tempClub)){
tempClub=newclub(redirectMap.get(tempClub));
计数--;
}否则{
完成=正确;
}
}而(!完成(&count)>0);
重定向ReturningUser(请求、响应、tempClub.getName());
}
void redirectReturningUser(HttpServletRequest请求、HttpServletResponse响应、字符串redirectUrl)引发IOException{
doRedirect(响应,“http://”+重定向URL);
}
私有void doRedirect(HttpServletResponse,字符串s)引发IOException{
响应。发送重定向;
}

我使用while循环来解决这个问题,结果成功了

while(registered==true){

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

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

谢谢,

如果用户订阅了另一个联赛,您想做什么?@Nambari,重定向到另一个俱乐部,直到他到达未订阅的俱乐部。@Nambari用户不能同时订阅所有4个俱乐部。至少有一个俱乐部他不会被订阅。例如,如果用户没有订阅成人俱乐部,则会显示成人.godaddy.mobi网页。如果用户订阅了多个俱乐部,您想做什么?@Roman。。用户发送订阅俱乐部(例如青年俱乐部)的请求,代码应检查他是否已订阅该俱乐部。如果他是这个俱乐部的新成员,他会出现在youthclub.yahoo.mobi的网页上。但是如果他已经订阅了这个俱乐部,那么他应该被自动重定向到成人俱乐部(成人。godaddy。mobi)的网页。代码应该再次检查他是否已经订阅了成人俱乐部,如果他已经订阅了这个俱乐部,那么他应该自动重定向到elder.google.mobi网页。@Roman。。谢谢你的密码。。但我需要一个解决方案,它会不断检查用户是否订阅了俱乐部。。如果他没有订阅,那么只进行重定向,否则它将继续检查哪个俱乐部用户没有订阅@MadanMadan我给了你一个主意,我不想为你写申请书。@Roman。。不,不是应用程序。。谢谢你的密码。。但它只适用于单个重定向,而不适用于检查用户是否已订阅第二个俱乐部的条件。。这是我的主要问题@MadanMadan遍历俱乐部,检查用户是否属于,并将结果保存在临时地图中。然后通过循环模拟重定向。完成后重定向到最后一个位置。不要忘记为
Club
创建
equals
hashCode
方法。
while(registered==true){

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

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