0
votes

I show a list of demandes on my jsp1 and when I choose one I wanna go to jsp2 show the demand details and allow people to comment below. I'm having this problem, when I send the selected demande and go to jsp2 I find this error : Cannot find bean: "demand" in scope: "request" Here's my code:

JSP1:

    <logic:iterate id="demande" name="demandes">
    <html:link  page ="/PAGES/commentaire.jsp" paramId="demand" 
                      paramName="demande" paramProperty="content">
    <bean:write name="demande" property="content" /><br>
    </html:link>
    </logic:iterate>

JSP2:

<bean:write name="demand"  scope="request"/>

I really dont know where the problem might come from, cuz every thing seems pretty right. Does anyone have an idea.

Seconde version: JSP1:

<html:link  page ="/show.do" paramId="demande" paramName="demande" >
            <bean:write name="demande" property="demandeId" /><br>
        </html:link>

struts-config.xml:

<action path="/show" 
                type="action.ActionAfficherDemande"             
                validate="true"
                input="/PAGES/JSP1.jsp"
                scope="session">
            <forward name="success" path="/PAGES/JSP2.jsp" redirect="true"/>            
 </action>

ActionAfficherDemande.java :

HttpSession session = request.getSession();
Demande myDemande = (Demande) session.getAttribute("demande");
1
One more thing, I can see the information, that I've sent, in the URL! - ABDO Zeidane
Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on Stack Overflow. See Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?. - rene

1 Answers

2
votes

You're using Struts. Struts is an MVC framework. The very simple rule of MVC is: all requests go to a controller, which prepares the model, and then forwards to a view. You should NEVER have a link to a JSP. Always to a controller. All your links should end with .do. Never with .jsp.

Also, you're confusing request parameters with request attributes. Request parameters are Strings that are sent by the browser to the server using a form, or a link with a query string (/foo.do?bar=baz for example). Request attributes are objects that are stored in the request by some component on the server, using request.setAttribute(). Your code expects to get the value of a parameter by getting the value of an attribute.