2015-03-24 111 views
0

我工作這個jsp,servlet和struts。 (Jsp版本2.0,servlet 2.4,struts 1)。 另一個「for」循環有一個。從JSP頁面中刪除Java代碼

... 
<% 
    String[] profileNames = { "Page", "Report", "XML API" }; 
    for (String profileName : profileNames) { 

     LRUCache profile = ObjectStore.getStore(profileName + " Profile"); 
     pageContext.setAttribute("profile", profile); 
     pageContext.setAttribute("profileName", profileName); 
%> 

<table class="sortable" id="<%=profileName%>"> 
    <tr class=title> 
     <th class=contentTable>description</th> 
     <th class=contentTable>qty</th> 
    </tr> 
    <c:forEach var="profile" items="${profileItems}"> 
     <tr> 
      <td>${profile.object.description}</td> 
      <td>${profile.object.qty}</td> 
     </tr> 
    </c:forEach> 
</table> 
<% 
    } 
%> 

我需要這個沒有java代碼的jsp頁面。如何實現它?

謝謝你的幫助!

回答

2

發送與您當前「放入」在Servlet上的pageContextprofileprofileName相同的屬性(或任何其他用於處理請求/響應的類似技術)。

類似於:request.setAttribute("key", value);關於Servlet類。

更新:我在這裏做了一個快速搜索,你可能真的想看看這個one

+0

謝謝你的幫助! 我可以調用帶有jsp頁面(版本2.0) 中的參數的java方法,如下所示:'ObjectStore.getStore(profileName +「Profile」);'? – Dan 2015-03-25 07:45:46

+0

當然,使用正確的'<%@ page import =「path.to.YourClass」%>'(在你的情況下'ObjectStore')指令是首先聲明的,你可以這樣做,但我強烈建議你只使用_use_數據儘管我也知道有時候需求和/或時間有點瘋狂,但從長遠來看,它更容易維護。基本上,你需要做的事情,例如在一個'Servlet'中,然後發送數據和渲染東西。這[鏈接](http://www.javatpoint.com/jsp-tutorial)非常有用。祝你有美好的一天! – 2015-03-25 12:18:35