Re: NEWBIE: How to pass parameters between JSPs
Hi Adam Glad it worked out. The ActionForm is the "Struts way" of interacting with HTML forms. It is a kkey concept of the Struts framework. So, what basically happens here is that an Action CAN be tied to a FormBean, and the FormBean serves as a "layer" between your HTML form and the action. So, all your action has to do, is to inspect the attributes of the FormBean to get to the data the user entered in the HTML form. The trick here is naming of html tags as you already figured out. I don't know what others on this list do, but as a rule of thumb I always use the constellation: JSP->FormBean->Action When polulating the jsp, you can also use the very same FormBean, to set up defaults, fill lists, whatever. It works in both directions. JSP->FormBean and FormBean->JSP HTH Henrik - Original Message - From: "Adam Lipscombe" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 3:37 PM Subject: RE: NEWBIE: How to pass parameters between JSPs Hi Henrik Yes that's it. I tried what you suggest and it works. Many thanks. What I was trying to avoid was storing the params in the LoginForm actionform. It seems like this approach uses the LoginForm ActionForm as a forwarding mechanism for params passed into Login.jsp. What I tried was this: In Login.jsp itself I stored the params in the request instance via setAttribute(). If I later try to fish them out in the Login action they are not available - because the request instance has changed. I did not use the ActionForm to pass them from Login.jsp to Login Action. Is using the ActionForm like you suggest the normal way to handle this situation? (i.e. "passing through" params). TIA - Adam -Original Message- From: HG [mailto:[EMAIL PROTECTED] Sent: 30 September 2004 14:14 To: Struts Users Mailing List Subject: Re: NEWBIE: How to pass parameters between JSPs Hi Adam I might be overwhelmed by the lack of sleep, but... I can simply don't get it.. So please confirm' 1 ) You have a login.jsp and a LoginAction 2) When the submit button (or whatever) is pressed on the rendered (by login.jsp) HTML page, LoginAction is called. 3) In LoginAction, you can get to the value of the fields (in login.jsp), through the attached FormBean (say LoginForm) instance. 4) You can take these values and store them as attributes on the request and forward (NOT redirect) to another action/jsp. 5) In the action/jsp you get these attributes again from the request Is the problem that you are using redirect?? It can be set up in the struts-config.xml Regards Henrik - Original Message - From: "Adam Lipscombe" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 2:01 PM Subject: RE: NEWBIE: How to pass parameters between JSPs Folks Thanks for your replies I tried using request.setAttribute(), but the HttpServletRequest instance changes between Login.jsp and the login action. The instance that Login.jsp stores the params in is not the same instance that is passed into the login action. Hence he params are not present in the login action. The param I want to pass is a Map of name/value pairs. Maybe the standard solution is to just put it in the session? TIA -Adam -----Original Message- From: HG [mailto:[EMAIL PROTECTED] Sent: 30 September 2004 12:32 To: Struts Users Mailing List Subject: Re: NEWBIE: How to pass parameters between JSPs Hi Andy A session variable can be "expensive". Why not just put it on the request by using "request.setAttribute" in one action and getting it again using "request.getAttribute" in another action? What is your "parameter"? A simple type, object, graph of objects? - Original Message - From: "andy wix" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 1:03 PM Subject: NEWBIE: How to pass parameters between JSPs > Hi, > > It's probably better to store them in the session rather then passing > from page to page. In Login action: > > HttpSession session = request.getSession(); > session.setAttribute("YourParams", params); > > and get them in the next page: > > YourClass xxx = > (YourClass)session.getAttribute("YourParams"); > > regards, > Andy > > _ > Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --
RE: NEWBIE: How to pass parameters between JSPs
Hi Henrik Yes that's it. I tried what you suggest and it works. Many thanks. What I was trying to avoid was storing the params in the LoginForm actionform. It seems like this approach uses the LoginForm ActionForm as a forwarding mechanism for params passed into Login.jsp. What I tried was this: In Login.jsp itself I stored the params in the request instance via setAttribute(). If I later try to fish them out in the Login action they are not available - because the request instance has changed. I did not use the ActionForm to pass them from Login.jsp to Login Action. Is using the ActionForm like you suggest the normal way to handle this situation? (i.e. "passing through" params). TIA - Adam -Original Message- From: HG [mailto:[EMAIL PROTECTED] Sent: 30 September 2004 14:14 To: Struts Users Mailing List Subject: Re: NEWBIE: How to pass parameters between JSPs Hi Adam I might be overwhelmed by the lack of sleep, but... I can simply don't get it.. So please confirm' 1 ) You have a login.jsp and a LoginAction 2) When the submit button (or whatever) is pressed on the rendered (by login.jsp) HTML page, LoginAction is called. 3) In LoginAction, you can get to the value of the fields (in login.jsp), through the attached FormBean (say LoginForm) instance. 4) You can take these values and store them as attributes on the request and forward (NOT redirect) to another action/jsp. 5) In the action/jsp you get these attributes again from the request Is the problem that you are using redirect?? It can be set up in the struts-config.xml Regards Henrik - Original Message - From: "Adam Lipscombe" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 2:01 PM Subject: RE: NEWBIE: How to pass parameters between JSPs Folks Thanks for your replies I tried using request.setAttribute(), but the HttpServletRequest instance changes between Login.jsp and the login action. The instance that Login.jsp stores the params in is not the same instance that is passed into the login action. Hence he params are not present in the login action. The param I want to pass is a Map of name/value pairs. Maybe the standard solution is to just put it in the session? TIA -Adam -Original Message- From: HG [mailto:[EMAIL PROTECTED] Sent: 30 September 2004 12:32 To: Struts Users Mailing List Subject: Re: NEWBIE: How to pass parameters between JSPs Hi Andy A session variable can be "expensive". Why not just put it on the request by using "request.setAttribute" in one action and getting it again using "request.getAttribute" in another action? What is your "parameter"? A simple type, object, graph of objects? - Original Message - From: "andy wix" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 1:03 PM Subject: NEWBIE: How to pass parameters between JSPs > Hi, > > It's probably better to store them in the session rather then passing > from page to page. In Login action: > > HttpSession session = request.getSession(); > session.setAttribute("YourParams", params); > > and get them in the next page: > > YourClass xxx = > (YourClass)session.getAttribute("YourParams"); > > regards, > Andy > > _ > Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: NEWBIE: How to pass parameters between JSPs
Hi Adam I might be overwhelmed by the lack of sleep, but... I can simply don't get it.. So please confirm' 1 ) You have a login.jsp and a LoginAction 2) When the submit button (or whatever) is pressed on the rendered (by login.jsp) HTML page, LoginAction is called. 3) In LoginAction, you can get to the value of the fields (in login.jsp), through the attached FormBean (say LoginForm) instance. 4) You can take these values and store them as attributes on the request and forward (NOT redirect) to another action/jsp. 5) In the action/jsp you get these attributes again from the request Is the problem that you are using redirect?? It can be set up in the struts-config.xml Regards Henrik - Original Message - From: "Adam Lipscombe" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 2:01 PM Subject: RE: NEWBIE: How to pass parameters between JSPs Folks Thanks for your replies I tried using request.setAttribute(), but the HttpServletRequest instance changes between Login.jsp and the login action. The instance that Login.jsp stores the params in is not the same instance that is passed into the login action. Hence he params are not present in the login action. The param I want to pass is a Map of name/value pairs. Maybe the standard solution is to just put it in the session? TIA -Adam -Original Message- From: HG [mailto:[EMAIL PROTECTED] Sent: 30 September 2004 12:32 To: Struts Users Mailing List Subject: Re: NEWBIE: How to pass parameters between JSPs Hi Andy A session variable can be "expensive". Why not just put it on the request by using "request.setAttribute" in one action and getting it again using "request.getAttribute" in another action? What is your "parameter"? A simple type, object, graph of objects? - Original Message - From: "andy wix" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 1:03 PM Subject: NEWBIE: How to pass parameters between JSPs > Hi, > > It's probably better to store them in the session rather then passing > from page to page. In Login action: > > HttpSession session = request.getSession(); > session.setAttribute("YourParams", params); > > and get them in the next page: > > YourClass xxx = > (YourClass)session.getAttribute("YourParams"); > > regards, > Andy > > _ > Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: NEWBIE: How to pass parameters between JSPs
Folks Thanks for your replies I tried using request.setAttribute(), but the HttpServletRequest instance changes between Login.jsp and the login action. The instance that Login.jsp stores the params in is not the same instance that is passed into the login action. Hence he params are not present in the login action. The param I want to pass is a Map of name/value pairs. Maybe the standard solution is to just put it in the session? TIA -Adam -Original Message- From: HG [mailto:[EMAIL PROTECTED] Sent: 30 September 2004 12:32 To: Struts Users Mailing List Subject: Re: NEWBIE: How to pass parameters between JSPs Hi Andy A session variable can be "expensive". Why not just put it on the request by using "request.setAttribute" in one action and getting it again using "request.getAttribute" in another action? What is your "parameter"? A simple type, object, graph of objects? - Original Message - From: "andy wix" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 1:03 PM Subject: NEWBIE: How to pass parameters between JSPs > Hi, > > It's probably better to store them in the session rather then passing > from page to page. In Login action: > > HttpSession session = request.getSession(); > session.setAttribute("YourParams", params); > > and get them in the next page: > > YourClass xxx = > (YourClass)session.getAttribute("YourParams"); > > regards, > Andy > > _ > Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: NEWBIE: How to pass parameters between JSPs
Forget my previous post. Was answering an answer... :-) Might need some sleep.. :-) - Original Message - From: "andy wix" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 1:03 PM Subject: NEWBIE: How to pass parameters between JSPs > Hi, > > It's probably better to store them in the session rather then passing from > page to page. > In Login action: > > HttpSession session = request.getSession(); > session.setAttribute("YourParams", params); > > and get them in the next page: > > YourClass xxx = (YourClass)session.getAttribute("YourParams"); > > regards, > Andy > > _ > Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: NEWBIE: How to pass parameters between JSPs
Hi Andy A session variable can be "expensive". Why not just put it on the request by using "request.setAttribute" in one action and getting it again using "request.getAttribute" in another action? What is your "parameter"? A simple type, object, graph of objects? - Original Message - From: "andy wix" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 30, 2004 1:03 PM Subject: NEWBIE: How to pass parameters between JSPs > Hi, > > It's probably better to store them in the session rather then passing from > page to page. > In Login action: > > HttpSession session = request.getSession(); > session.setAttribute("YourParams", params); > > and get them in the next page: > > YourClass xxx = (YourClass)session.getAttribute("YourParams"); > > regards, > Andy > > _ > Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]