• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Html:link forward +parameter passing  RSS feed

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys need some more help.

I have to pass a string value in the <html:link forward> based on this value passed i have to show the corresponding JSP page.

How do i pass the value and how do i retrieve it back to make the decision
It gives me the following error:-
Cannot find bean add_Promof in any scope...

so do i have to define a bean specifically for that..if yes how...Please

Thanks In advance,
Sahil



[ May 26, 2004: Message edited by: Sahil Singh ]
[ May 26, 2004: Message edited by: Sahil Singh ]
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
was trying to use my own "Intelligence"...
Is this how it shd be..? please correct me..

for passing a single parameter from one JSP to Next using <html:link> tag :--

<html:link forward="nextPage" paramId="the attribute by which i shall retrieve the value enclosed in paramName" paramName="distinctValue" />

Thanks,
Sahil
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better explaining my situation :-

<html:link forward="nextPage" paramId="Param" paramName="StringA" />
<html:link forward="nextPage" paramId="Param" paramName="StringB" />
<html:link forward="nextPage" paramId="Param" paramName="StringC" />


And on the "nextpage"...

String test = (String)request.getAttribute("Param");

or there is a better way...



** Is it necessary for the JSP1 to pass thru an Action class to go to JSP2.....???



Is this Correct...Pl...i have to implement it urgently..

Thanks,
Sahil

[ May 26, 2004: Message edited by: Sahil Singh ]
[ May 26, 2004: Message edited by: Sahil Singh ]
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sahil Singh:

And on the "nextpage"...

String test = (String)request.getAttribute("Param");

or there is a better way...


You may want to consider using DispatchAction or DispatchLookupAction for selecting forwards, based on query parameters. It's extremely easy to use and highly flexible.


** Is it necessary for the JSP1 to pass thru an Action class to go to JSP2.....???


Not at all. Add this into action-mapping section.

You can also use page or href attribute of the <html: link> tag to directly point to a url within the application, though I would not use it.

I read somewhere in Struts In Action, that, it's always a great idea to front your pages with an Action. It always allows you to control things better.

Just my two cents !

Thanks and regards,
Kinjal Sonpal
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,


Thanks for the answer..still have the same problem

It says "Cannot find bean StringA in any scope"

In Jsp1 i have :-

<html:link forward="add_PRODUCT" paramId="Param" paramName="StringA" />
<html:link forward="add_PRODUCT" paramId="Param" paramName="StringB" />
<html:link forward="add_PRODUCT" paramId="Param" paramName="StringC" />



In JSP2 i have :-
As Explained String hh = request.getAttribute("Param");


In Config :-
<global-forwards>
<forward name="add_PRODUCT" path="/pages/JSP2.jsp"/>
</global-forwards>
<action path="/pages/add_PRODUCT"
type="org.apache.struts.actions.ForwardAction"
parameter="/pages/JSP2.jsp" />


I am sure i am missing something else..but what?

Thanks Again..
Sahil
[ May 27, 2004: Message edited by: Sahil Singh ]
 
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
paramName is not a string you can hardcode - it is supposed to be a reference to an scoped String attribute.

What you want to accomplish seems more like a hardcoded approach. You can accomplish this by putting the parameters into your forward and splitting it up into multiple forwards.

<html:link forward="add_PRODUCT_A" />
<html:link forward="add_PRODUCT_B" />
<html:link forward="add_PRODUCT_C" />

In Config :-
<global-forwards>
<forward name="add_PRODUCT_A" path="/pages/JSP2.jsp?PARAM=StringA"/>
<forward name="add_PRODUCT_B" path="/pages/JSP2.jsp?PARAM=StringB"/>
<forward name="add_PRODUCT_C" path="/pages/JSP2.jsp?PARAM=StringC"/>
</global-forwards>
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Saviour Has Done it Again....!!!

to you all and this Forum.......

Thanks,
Sahil
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here again......

So if do have multiple values,then what is the relation with "BEAN"....

I understand that u put it in a map with key and value pair...but what is the relationship with a <bean efine> or is it <bean:write>???

I tried to put the same as explained in this earlier post this way but could not get it.

SO in short how do i get to pass the above parameter/multiple parameters ...from i JSP to Another...(Apart from the way explained by Marc...)

Thanks,
Sahil

[ May 30, 2004: Message edited by: Sahil Singh ]
[ May 30, 2004: Message edited by: Sahil Singh ]
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not finished yet....
 
Kinjal Sonpal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far what I have understood to be the problem is : You want a link to
pass multiple query parameters dynamically built. If this is the problem, the following may be able to give you a lead.

1) Define a map containing key value pair in any accessible scope. Key from the map is assumed to be the parameter name and it's corresponding value will be appended as parameter value. Say, an Action after preparing such a map puts it in Session scope, like this
2) In the jsp page, use

I understand that u put it in a map with key and value pair...but what is the relationship with a <bean: define> or is it <bean: write>???


There is no relationship as such for <bean: define>. It only helps us to bring a bean, which either itself is java.util.Map or has an accessor property for the Map. Since the links are built dyanmically, we may also want some dynamically built anchor text as well. <bean: write> helps us to do that. As you can see, it is used in the sample code as well.

Please let me know for any further clarification. Though here I've used
session scope for simplicity, in my real life project I would prefer to use
a formbean containing a getter method for the map. This form would be
populated by an Action.

You can also refer to Struts taglib API for further guidance. It's an excellent source of information.

HTH.

Thanks and regards,
Kinjal Sonpal
[ June 02, 2004: Message edited by: Kinjal Sonpal ]
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Kinjal Thanks for responding.

I understood somewhat of the above...not so smart i guess..

Supposing i have 2 (or more..) parameter valuse like for ex:-

String A = "Jan";
String B = "Feb";
...

the next step would be ...

HashMap myMap = HashMap();
hm.put("A",A);
hm.put("B",B);

session.setAttribute ("myMap", myMap);

<html:link action="/inquiry" name="myMap" transaction="true" scope="session">
<bean:write name="inquiryHdrRow" property="subject"/>
</html:link>


---- and the on the next JSP...
String test = request.getParameter("A");..???

Sorry have limited scope in terms of "Intelligence"


Thanks,
Sahil.
[ June 02, 2004: Message edited by: Sahil Singh ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sahil,

You may also want to try out something like the below code snippet for forwarding :-)

<html>
<head>
<meta http-equiv="Refresh" content="0; url=http://www.hotmail.com">
</head>
<body>
</body>
</html>

Cheers,
Amit.
 
Kinjal Sonpal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Sahil Singh:
Supposing i have 2 (or more..) parameter valuse like for ex:-
String A = "Jan";
String B = "Feb";
...
the next step would be ...
HashMap myMap = HashMap();
hm.put("A",A);
hm.put("B",B);
session.setAttribute ("myMap", myMap);
...
<html:link action="/inquiry" name="myMap" transaction="true" scope="session">
<bean:write name="inquiryHdrRow" property="subject"/>
</html:link>
---- and the on the next JSP...
String test = request.getParameter("A");..???


Just perfect ! This is what I do to get things working. However, one of the biggest disadvantage of this is, somewhere you may have a situation, where you are exposing sensitive information in the URL itself.

Let me know for any further queries. I'll try to answer a little more quickly.

Thanks and regards,
Kinjal Sonpal
 
Kinjal Sonpal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Amit Shanker:
You may also want to try out something like the below code snippet for forwarding :-)
<html>
<head>
<meta http-equiv="Refresh" content="0; url=http://www.hotmail.com">
</head>
<body>
</body>
</html>



Amit, AFAIK, this code snippet would fire a new request from the browser. If you have some data, which needs to be available only in request scope, things would go for a toss.

I'm no way near the experts on Struts, but I think this also defeats one of the purposes Struts Framework. With Struts, we have almost entire flow control of the application within the config file and hence, in the hands of the controller. By this, we are forking off the flow control. To the best of my knowledge, this should be used to fire external URLs only.

My two cents.

Thanks and regards,
Kinjal Sonpal
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!