Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I send a parameter from my Action to my jsp?

Status
Not open for further replies.

SuperMoonster

Programmer
Aug 11, 2005
59
BR
Hello,

I am having problems in sending a parameter from my action to my jsp. I want to know what I gotta do to get the parameter in the jsp.

My action is the following:

<tt>
public class ListaColecaoAction extends Action{
public ActionForward execute (
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {

List lista = ColecaoService.getInstance().getColecaoList();
request.setAttribute("col", lista);
return mapping.findForward("ok");

}
}
</tt>

As you see, I did a "request.setAttribute("col", lista);", but it doesn't seem enough.

I am trying to get it in my jsp with a logic:iterate like this:

<tt>
<logic:iterate id="element" name="col" scope="request" type="auge.bean.Colecao" >
<tr>
<td><bean:write name="element" property="colecao" /></td>
<td><bean:write name="element" property="descricao" /></td>
</tr>
</logic:iterate>
</tt>

but it gives me the error "cannot find bean col in scope request". I know the problem is only regarding the parameter, because when I put a scriplet to call the method in the jsp, is worked perfectly. But I don't wanna use the scriplet.

What do I gotta do to make ir work? What if I want to use JSTL (c:forEach)?

Thank you all
 
Hi,

Below is the example of how to use logic:iterate and JSTL fro Each. In the below example I am using LabelValueBean insted of "Colecao" which you are using and I am not using the action in this example just putting the list in request scope of the page.

Hope this will help you,

Code:
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="[URL unfurl="true"]http://java.sun.com/jstl/core"[/URL] prefix="c"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="java.util.*, org.apache.struts.util.LabelValueBean"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
  </head>
  <body>
  <%
    ArrayList list = new ArrayList();
    list.add(new LabelValueBean("one","1"));
    list.add(new LabelValueBean("two","2"));
    pageContext.setAttribute("list", list, PageContext.REQUEST_SCOPE);
    
  %>
 
  
    Example using JSTL
    </br>
    <c:forEach var="lBean" items="${requestScope.list}" varStatus="idx">
      <c:out value="${lBean.label}"/>
      <c:out value="${lBean.value}"/>
      </br>
    </c:forEach>
    </br>
    Example using Logic Iterate
    </br>
    <logic:iterate id="lBean1" name="list" scope="request">
      <bean:write name="lBean1" property="label" />
      <bean:write name="lBean1" property="value" />
      </br>
    </logic:iterate>
   </body>
</html>

Cheers
Venu
 
I understand what you did, and it works for me (as I told before, scriplets work)

The problem is that when i try to save an attribute in my action with " request.setAttribute("col", lista);", it doesn't work.

Maybe there's something wrong with the way I am recovering it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top