2015-03-24 106 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