###Javaのfor文の処理が反映されません
まずは、下記に該当するクラスを載せます
lang
1package search; 2 3import java.io.IOException; 4import java.util.HashMap; 5import java.util.LinkedList; 6import java.util.Map; 7 8import javax.servlet.ServletException; 9import javax.servlet.annotation.WebServlet; 10import javax.servlet.http.HttpServlet; 11import javax.servlet.http.HttpServletRequest; 12import javax.servlet.http.HttpServletResponse; 13import javax.servlet.http.HttpSession; 14 15import profile.Ngram; 16import beans.ClientBeans; 17import beans.EngineerBeans; 18import dao.SearchClientDao; 19 20@WebServlet(name = "SearchClientList" , urlPatterns = { "/SearchClientList" }) 21public class SearchClientList extends HttpServlet{ 22 private static final long serialVersionUID = 1L; 23 Map<Integer , Integer> industryMap = new HashMap<>(); 24 Map<Integer , Integer> typeOfIndustryMap = new HashMap<>(); 25 26 @Override 27 protected void doGet(HttpServletRequest request, HttpServletResponse response) 28 throws ServletException, IOException { 29 request.setCharacterEncoding("utf8"); 30 HttpSession ses = request.getSession(true); 31 int engineerid = (int)ses.getAttribute("engineerid"); 32 SearchClientDao searchClientDao = new SearchClientDao(); 33 EngineerBeans bengineerBeans; 34 LinkedList<ClientBeans> clientList = new LinkedList<>(); 35 try{ 36 searchClientDao.connect(); 37 searchClientDao.selectSearchClient(engineerid); 38 String place = searchClientDao.selectSearchClient(engineerid).getDemand_place(); 39 Map<String, Integer> map = Ngram.createNgram(place, 2); 40 int price = searchClientDao.selectSearchClient(engineerid).getDemand_price(); 41 int price_min = 0; 42 int price_max = 0; 43 if(price == 1){ 44 price_min = 21; 45 price_max = 40; 46 }else if(price == 2){ 47 price_min = 41; 48 price_max = 60; 49 }else if(price == 3){ 50 price_min = 61; 51 price_max = 80; 52 }else if(price == 4){ 53 price_min = 81; 54 price_max = 100; 55 }else if(price == 5){ 56 price_min = 101; 57 price_max = 200; 58 } 59 searchClientDao.selectSearchIndustry(engineerid); 60 int industry1 = searchClientDao.selectSearchIndustry(engineerid).getIndustry1(); 61 industryMap.put(1, industry1); 62 int industry2 = searchClientDao.selectSearchIndustry(engineerid).getIndustry2(); 63 industryMap.put(2, industry2); 64 int industry3 = searchClientDao.selectSearchIndustry(engineerid).getIndustry3(); 65 industryMap.put(3, industry3); 66 67 searchClientDao.selectSearchTypeOfIndustry(engineerid); 68 int type_of_industry1 = searchClientDao.selectSearchTypeOfIndustry(engineerid).getType_of_industry1(); 69 typeOfIndustryMap.put(1, type_of_industry1); 70 int type_of_industry2 = searchClientDao.selectSearchTypeOfIndustry(engineerid).getType_of_industry2(); 71 typeOfIndustryMap.put(1, type_of_industry2); 72 int type_of_industry3 = searchClientDao.selectSearchTypeOfIndustry(engineerid).getType_of_industry3(); 73 typeOfIndustryMap.put(1, type_of_industry3); 74 75 for (Map.Entry<String, Integer> entry : map.entrySet()) { 76 String place_piece = entry.getKey(); 77 System.out.println(place_piece); 78 for(int i = 1; i < industryMap.size(); i++){ 79 for(int j = 1; j < typeOfIndustryMap.size(); j++){ 80 int industry_num = industryMap.get(i); 81 int type_of_industry_num = typeOfIndustryMap.get(j); 82 System.out.println(industry_num); 83 System.out.println(type_of_industry_num); 84 clientList.addAll(searchClientDao.searchClientList(place_piece , price_min , price_max , type_of_industry_num , industry_num)); 85 } 86 } 87 } 88 89 request.setAttribute("clientList", clientList); 90 searchClientDao.close(); 91 request.getRequestDispatcher("MatchingList_engineer.jsp").forward(request, response); 92 }catch(Exception e){ 93 e.printStackTrace(); 94 } 95 } 96 97 @Override 98 protected void doPost(HttpServletRequest request, HttpServletResponse response) 99 throws ServletException, IOException { 100 doGet(request, response); 101 } 102}
上記のクラスでデータベースのデータを取得して、
JSPでそのデータを表示させようとしています。
該当の処理がされない箇所が以下の部分です。
lang
1for (Map.Entry<String, Integer> entry : map.entrySet()) { 2 String place_piece = entry.getKey(); 3 System.out.println(place_piece); 4 for(int i = 1; i < industryMap.size(); i++){ 5 for(int j = 1; j < typeOfIndustryMap.size(); j++){ 6 int industry_num = industryMap.get(i); 7 int type_of_industry_num = typeOfIndustryMap.get(j); 8 System.out.println(industry_num); 9 System.out.println(type_of_industry_num); 10 clientList.addAll(searchClientDao.searchClientList(place_piece , price_min , price_max , type_of_industry_num , industry_num)); 11 } 12 } 13 }
ここが丸々処理されずにJSPにディスパッチしてしまいます。
処理自体は間違っている可能性大ですので、気にしないで下さい笑
原因が全くわかりませんので、
ご教授いただけるとありがたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/06/25 05:22
2015/06/25 06:15
2015/06/25 06:57 編集
2015/06/25 08:47