나의질문답

뒤로가기 버튼시 데이터 가지고 있다가 보여주기

예쁜꽃이피었으면 2014. 11. 11. 14:27



//검색리스트 세션저장

HttpSession session = request.getSession();

if(session.getAttribute("result_".concat(fileName)) != null){

request.setAttribute("plantList", session.getAttribute("result_".concat(fileName)));

else{

어쩌고 저쩌고 소스


  // 검색결과 세션저장...

         session.setAttribute("result_".concat(fileName),articleList);

         

}


해결







지금 하려는게

1. 사용자가 식물 이미지 검색을 한 후 검색결과 리스트 10개를 보여준다.

2. 검색결과 리스트의 상세 이미지를 보고 난 후에 다시 뒤로 가기 버튼을 누른다.

3. 뒤로 가기를 하면 이전에 검색했던 검색결과 리스트 10개를  보여준다.


인데.


아래 소스는 검색결과까지는 가지고 다시 검색하는 소스코드 부분에 왔다.

그런데,검색결과 리스트가 문자열 형태라 잘라서 배열에 넣어서 arraylist에 넣었다.


이 새로 만든 arraylist가 검색이 안된다. 

어째서 일까.






ArrayList<plant> articleList = new ArrayList<plant>();

ArrayList<String> articleList2 = new ArrayList<String>();

String plantList  = request.getParameter("getplantList");///////////////////**********

System.out.println("plantList************ "+ plantList);

if(plantList != null){ 

// 앞뒤 [  ] 잘라야하나  어차피 articleList2출력해보면 또 붙어있음.

//2개씩있음 잘라야 하나봄

String plantList_split  = plantList.replaceAll("\\[" , "");

System.out.println("plantList_split-------------"+plantList_split);

String plantList_split2  = plantList_split.replaceAll("\\]", "");

System.out.println("plantList_split2-------------"+plantList_split2);

String[] array = plantList_split2.split(","); 

//String[] array = plantList.split(","); 

for(int i=0; i < array.length; i++){

System.out.format("array[%d] = %s%n", i,array[i]);

}

Collections.addAll(articleList2, array); 

for (int i = 0; i < array.length; i++) { 

System.out.format("articleList2[%d] = %s%n", i, articleList2.get(i)); 

  //새로 검색하지 않고 검색리스트 보기가 가능해지면 ?

   request.setAttribute("plantList", articleList2);

   System.out.println("13****articleList2*****" + articleList2);

 //return "plantlistdata.jsp";

}



//1.어떻게 하면 articleList2를 가지고 검색이 될까

//2. articleList2가 ArrayList<plant> 가 아니라서 검색이 안되는걸까?

//3.밑에 검색 소스를 안타게 하던지..바로 return되어야 할 것 같은데,,

//4.articleList2는 왜 <plant>가 아닌 <String>형태여야 하는가.




*addAll() 메소드의 매개변수의 Collection<? extends E> 중 '? extends E'가 의미하는 것은

요소 클래스형 E를 상속받는 모든 클래스라는 의미다. 

예를 들어 String의 경우 String을 상속받는 모든 클래스로 이뤄진 Collection객제를 매개변수로 받을 수 있다.


-> 그렇다면 array를...제네릭형으로 만들면 된다는 것인가? 





반응형