在while循环中请求调度程序

时间:2015-04-05 16:10:07

标签: java servlets

我的实际代码:

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(...)?请帮忙!

1 个答案:

答案 0 :(得分:0)

使用.forward它完全取消了对servlet的控制并将其转发到另一个jsp页面,但我们可以使用.include它只保留在当前的servlet中,只需要包含所需的jsp页面。