2012-01-27 2 views
0

0과 n - 1 사이에 정렬 된 m 개의 숫자 목록을 반환해야하는 다음 코드가 있습니다. 목록이 수정되었지만 JSP가 아무것도 인쇄하지 않는다는 것을 확인했습니다. 아무도 이것으로 나를 도울 수 있습니까? 이것이 저의 액션 클래스에있는 메소드입니다.JSTL 값이 인쇄되지 않습니다.

public static SortedSet<Integer> createCombo(int items, int maxNum) { 
    if (items > maxNum) { 
     System.out 
       .println("Cannot create a combination longer than the highest possible number."); 
     return null; 
    } 

    for (int i = 1; i <= items; i++) { 
     int newNum = 0; 
     boolean distinctNumber = false; 
     while (! distinctNumber) { 
      newNum = (int) Math.floor(Math.random() * maxNum); 
      distinctNumber = true; 

      if (i > 1) { 
       Iterator<Integer> iterator = combo.iterator(); 
       while ((iterator.hasNext()) && (distinctNumber)) { 
        if (newNum == iterator.next()) { 
         distinctNumber = false; 
        } 
       } 
      } 
     } 
     combo.add(newNum); 
    } 

    printCombo(); 
    return combo; 
} 

이것은 내 컨트롤러 클래스의 메서드입니다.

public String execute() { 
    SortedSet<Integer> combo = new TreeSet<Integer>(); 

    try { 
     if ((items == 0) || (maxNum == 0)) { 
      return "failure"; 
     } 
     combo = Combo.createCombo(items, maxNum); 
     if (combo != null) { 
      HttpSession session = (HttpSession) request.getSession(); 
      session.setAttribute("combo", combo); 
     } 

     return "success"; 
    } catch (Exception e) { 
    } 
    return "failure"; 
} 

이것은 내 JSP입니다. 내 브라우저에는 h1 태그 사이의 텍스트 만 나타납니다.

<%@ page import="java.io.*"%> 
<%@ page import="java.util.List"%> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="s" uri="/struts-tags"%> 
<html> 
<head> 
<title>Lotto Results</title> 
</head> 
<body> 
<center> 
<h1>Lotto Results</h1> 
</center> 
<s:iterator value="combo"> 
     <c:forEach var="iterator" items="${combo.iterator}" > 
      ${iterator.next} 
     </c:forEach> 
</s:iterator> 
</body> 
</html> 
+0

브라우저에서 오른쪽 클릭하고 * 소스보기 *. JSP로 생성 된 HTML 출력에서 ​​무엇을 볼 수 있습니까? 모든 JSP 태그가 파싱 되었습니까? – BalusC

+0

아니요, 아무도 파싱되지 않습니다. –

+2

* Struts 태그를 포함한 이들 중 아무 것도 *? JSTL 구현을 전개하고 있습니까? EL 평가를 위해 web.xml이 2.5 이상으로 설정되어 있습니까? 또한 정확히 무엇을하고 있습니까? 왜리스트를 하나의리스트에 넣고, 왜 하나의리스트를 반복하기 위해 두 개의 iterator 태그를 가지고 있습니까? –

답변

0

나는 내 자신의 문제를 해결했습니다. s : iterator 태그를 제거하고 내부에 반복 루프를 유지하고 다음과 같이 변경하여 이러한 변경 작업을 수행했습니다.

<c:forEach var="combo" items="${combo}"> 
    ${combo} 
</c:forEach> 
0

콤보는 액션 클래스의 속성이어야하며, 당신은 컬렉션을 반환하는 방법 getCombo()이 있어야합니다. 그런 다음 값이 표시됩니다.

내가 작업 클래스의 속성과 방법 getSongs로 노래를해야한다, 나는 반복하기 AlbumInfoAction

package vaannila; 

public class Song { 

    private String title; 
    private String genre; 

    Song(String title, String genre) 
    { 
     this.title = title; 
     this.genre = genre; 
    } 
    public String getTitle() { 
      return title; 
    } 
    public void setTitle(String title) { 
      this.title = title; 
    } 
    public String getGenre() { 
      return genre; 
    } 
    public void setGenre(String genre) { 
      this.genre = genre; 
    } 
} 

package vaannila; 

import java.util.ArrayList; 
import java.util.List; 


public class AlbumInfoAction{ 

private String title; 
private Artist artist; 
private static List&lt;Song&gt; songs = new ArrayList&lt;Song&gt;(); 

    static { 
     songs.add(new Song("Thriller","Disco")); 
     songs.add(new Song("Beat It","Rock")); 
     songs.add(new Song("Billie Jean","Pop")); 
    } 

    public String populate() 
    { 
     title = "Thriller"; 
     artist = new Artist("Michael Jackson","King of pop"); 
     return "populate"; 
    } 

    public String execute() 
    { 
     return "success"; 
    } 

    public String getTitle() { 
     return title; 
    } 
    public void setTitle(String title) { 
     this.title = title; 
    } 
    public Artist getArtist() { 
     return artist; 
    } 
    public void setArtist(Artist artist) { 
     this.artist = artist; 
    } 

    public List&lt;Song&gt; getSongs() { 
     return songs; 
    } 

} 

라고 노래 및 액션라는 클래스를했습니다, 예를 참조하십시오이 있어야합니다.

는 JSP 코드는이 도움이

<table class="songTable"> 
<tr class="even"> 
<td><b>Title</b></td> 
<td><b>Genre</b></td> 
</tr> 
<s:iterator value="songs" status="songStatus"> 
<tr 
class="<s:if test="#songStatus.odd == true ">odd</s:if><s:else>even</s:else>"> 
<td><s:property value="title" /></td> 
<td><s:property value="genre" /></td> 
</tr> 
</s:iterator> 
</table> 

희망과 같을 것이다.

+0

링크가 도달 할 수없는 경우에도이 답변이 도움이 될 것이라고 생각하십니까? 아니? 그 때 대답을 향상 시키십시오. – BalusC

+0

제안 해 주셔서 감사합니다. 답변을 개선했습니다. –