2015-04-05 44 views
0

我的實際代碼:請求調度

String input = "ECE&&non teaching staffs.*"; 
try{ 
    FileInputStream fstream = new FileInputStream("data1.txt"); 
    DataInputStream in = new DataInputStream(fstream); 
    BufferedReader br = new BufferedReader(new InputStreamReader(in)); 
    String strLine; 
    while ((strLine = br.readLine()) != null) { 
     if(Pattern.matches(in Pattern pattern = Pattern.compile("'put,strLine)){(.*?)'"); 
      Matcher mt = pattern.matcher(strLine); 
     while (mt.find()) { 
      String b=mt.group(1); 
      request.setAttribute("a",a); 
      String c=b.toString()+".*"; 
      FileInputStream fsstream = new FileInputStream("data1.txt"); 
      DataInputStream inn = new DataInputStream(fsstream); 
      BufferedReader bfr = new BufferedReader(new InputStreamReader(inn)); 
      String stringLine; 
      while ((stringLine = bfr.readLine()) != null) { 
       if(Pattern.matches(c,stringLine)){ 
        Pattern pat = Pattern.compile("#(.*?)#"); 
        Matcher mat = pat.matcher(stringLine); 
        while (mat.find()) { 
         String g=mat.group(1); 
         request.setAttribute("a",a); 
        } 
       } 
      } 
     } 
    } 
} 
} 
catch(Exception e){ 
    System.err.println("Error: " + e.getMessage()); 
} 

如何使用請求調度器在servlet while循環一樣

while(...) 
{ 
    String a="anything"; 
    request.setAttribute("a",a); 

    while(...) 
    { 
     String b="anything else"; 
     request.setAttribute("a",a); 
    } 

    request.getRequestDispatcher("/output.jsp").forward(request, response); 
} 

在這種情況下,它只是提供了一個打印使用一些值價值和while作品只有一次 究竟放在哪裏請求調度,使while環路工程和是否使用forward(...)與否?請幫忙 !

+0

什麼時候繼續的條件? – Razib 2015-04-05 16:13:26

+0

其實我剛剛給出了一個演示代碼,在我的實際代碼中while循環包含FileRead的條件,因爲我正在從文本文件中讀取值----- while((strLine = br.readLine()))! = null){..}請求調度程序如何創建問題爲什麼一會兒不工作? – 2015-04-05 16:18:57

+0

從你的帖子看來,while循環中的條件可能有問題。現在,你的評論似乎你正在嘗試閱讀一個文本文件。你的文本文件只包含一行嗎? – Razib 2015-04-05 16:24:23

回答

0

使用的.forward它完全帶走了Servlet的控制,並將其轉發到另一個JSP頁面,但我們可以用它.INCLUDE停留在當前的servlet纔剛剛包括任何需要的地方所需要的JSP頁面。