开发者

Passing string to popup

I'm working with a JSP page and it's displaying a table of a storage objects that was fetched. I want to have a popup to another JSP page when the user clicks on the number that is showing the size of the storage object.

How do I pass the name of the specified storage item to the popup JSP window with Javascript (or any other technique), and then retrieve that name in the popup JSP and be able to use it in that page's code?

The scriptlet for-loop looks like this:

<% for(Storage s : someList){ %>
   <tr>
      <td> <%= s.getName() %> </td> &l开发者_如何转开发t;td> <%= s.getSize() %> </td>
   </tr>
<% } %>


Pass it as request parameter.

E.g.

<td onclick="window.open('popup.jsp?name=<%= URLEncoder.encode(s.getName(), "UTF-8") %>', 'windowname')">

with in popup.jsp:

<%= request.getParameter("name") %>

Or, more cleanly, with JSTL and EL:

<c:forEach items="${someList}" var="s">
  <c:url value="popup.jsp" var="popupUrl">
    <c:param name="name" value="${s.name}" />
  </c:url>
  <tr>
    <td>${s.name}</td><td onclick="window.open('${popupUrl}', 'windowname')">${s.size}</td>
  </tr>
</c:forEach>

with in popup.jsp

${param.name}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜