You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Julia Weaver <dr...@yahoo.com> on 2004/04/27 00:10:02 UTC

name="params" in ?

Hi all,

Please advise:
I know how to pass params when use <html:link> tag.
But if I want to <html:submit> tag instead, what I
should use to replace: name="params"? Since I cannot
use: <html:submit property="action" name="params" /> 


This is in my jsp:

<%	
java.util.HashMap params = new java.util.HashMap();
		params.put("toolId", "thisId");
		params.put("toolName", "thisName" );	  
request.getSession(true).setAttribute("params",
params);			
%>
	
<html:link page="/GetChildTool.do" name= "params" >
	<bean:write name="tool" property="ToolNbr"/>
</html:link>
	


	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25�
http://photos.yahoo.com/ph/print_splash

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: name="params" in ?

Posted by Riyad Kalla <rs...@email.arizona.edu>.
Ahh ok I got you know, comments below:

Julia Weaver wrote:

>Thank you Riyad,
>
>Yes I want to do:
>  
>
>>If you are asking how you can (a) create that
>>HashMap in a sciplet in a JSP 
>>page AND put it into the session THEN (b) submit to
>>an Action and get it back 
>>out of the session,
>>    
>>
>
>
>
>In My jsp:
><%
>java.util.HashMap params2 = new java.util.HashMap();
>params2.put("p1", "1");	
>params2.put("p2", "2");	
>request.getSession(true).setAttribute("params2",
>params2);
>%>	
>
>In my action class:
>String params2 =
>(String)request.getSession(true).getAttribute("params2");
>  
>
This is the problem, in your JSP page you are putting a HashMap into 
your session, then in your action you get getting the HashMap out, and 
casting it to a String. Keep in mind there is NOTHING fancy about a 
Session, its just a Hashtable. So if you put a HashMap in, from your JSP 
page, then the only way you will get it out, is if you cast it 
correctly. Your action code should look like:
HashMap params2 = (HashMap)request.getSession(true).getAttribute("params2");
System.out.println(params2.get("p1"); //output "1"
System.out.println(params2.get("p2"); // output "2"

Anytime you get confused about sessions or requests and the 
get/setAttribute methods... remember they are just wrappers to 
Hashtables and it all becomes clear again.

Best,
Riyad

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: name="params" in ?

Posted by Julia Weaver <dr...@yahoo.com>.
Thank you Riyad,

Yes I want to do:
> If you are asking how you can (a) create that
> HashMap in a sciplet in a JSP 
> page AND put it into the session THEN (b) submit to
> an Action and get it back 
> out of the session,



In My jsp:
<%
java.util.HashMap params2 = new java.util.HashMap();
params2.put("p1", "1");	
params2.put("p2", "2");	
request.getSession(true).setAttribute("params2",
params2);
%>	

In my action class:
String params2 =
(String)request.getSession(true).getAttribute("params2");

But now I have this error:
[java/util/HashMap incompatible with
java/lang/String]: java.lang.ClassCastException:
java/util/HashMap incompatible with java/lang/String

Please give me further advice.



--- Riyad Kalla <rs...@email.arizona.edu> wrote:
> If you are asking how you can (a) create that
> HashMap in a scriplet in a JSP 
> page and then (b) submit it to an Action, my answer
> is "I don't know".
> 
> If you are asking how you can (a) create that
> HashMap in a sciplet in a JSP 
> page AND put it into the session THEN (b) submit to
> an Action and get it back 
> out of the session, my answer is "no problem, just
> do a 
> request.getSession().getAttribute("params"); from
> within the action, you 
> don't need to setup anything in your html:form"
> 
> 
> On Monday 26 April 2004 03:45 pm, Julia Weaver
> wrote:
> > Thanks for your response.
> > What I mean is without use any link on the page,
> only
> > use submit buttons, how can I get parameters? plus
> the
> > page has multiple submit buttons, so I have to use
> > LookupDispatchAction.
> >
> > --- Riyad Kalla <rs...@email.arizona.edu> wrote:
> > > I'm not terribly clear on what you are asking...
> > > your line:
> > > request.getSession(true).setAttribute("params",
> > > params);
> > >
> > > sets the 'params' variable in your session, so
> your
> > > link could actually just
> > > be a plan HTML link:
> > > <a href="/myapp/GetChildTool.do">Get Tool</a>
> > >
> > > and your action could still pull params out of
> your
> > > session and process it.
> > >
> > > Am I missing something?
> > >
> > > On Monday 26 April 2004 03:10 pm, Julia Weaver
> > >
> > > wrote:
> > > > Hi all,
> > > >
> > > > Please advise:
> > > > I know how to pass params when use <html:link>
> > >
> > > tag.
> > >
> > > > But if I want to <html:submit> tag instead,
> what I
> > > > should use to replace: name="params"? Since I
> > >
> > > cannot
> > >
> > > > use: <html:submit property="action"
> name="params"
> > >
> > > />
> > >
> > > > This is in my jsp:
> > > >
> > > > <%
> > > > java.util.HashMap params = new
> > >
> > > java.util.HashMap();
> > >
> > > > 		params.put("toolId", "thisId");
> > > > 		params.put("toolName", "thisName" );
> > > >
> request.getSession(true).setAttribute("params",
> > > > params);
> > > > %>
> > > >
> > > > <html:link page="/GetChildTool.do" name=
> "params"
> > > >
> > > > 	<bean:write name="tool" property="ToolNbr"/>
> > > > </html:link>
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > > > Yahoo! Photos: High-quality 4x6 digital prints
> for
> > >
> > > 25�
> > >
> > > > http://photos.yahoo.com/ph/print_splash
> >
> >
>
---------------------------------------------------------------------
> >
> > > > To unsubscribe, e-mail:
> > >
> > > user-unsubscribe@struts.apache.org
> > >
> > > > For additional commands, e-mail:
> > >
> > > user-help@struts.apache.org
> >
> >
>
---------------------------------------------------------------------
> >
> > > To unsubscribe, e-mail:
> > > user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail:
> > > user-help@struts.apache.org
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Photos: High-quality 4x6 digital prints for
> 25�
> > http://photos.yahoo.com/ph/print_splash
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> user-help@struts.apache.org
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: name="params" in ?

Posted by Riyad Kalla <rs...@email.arizona.edu>.
If you are asking how you can (a) create that HashMap in a scriplet in a JSP 
page and then (b) submit it to an Action, my answer is "I don't know".

If you are asking how you can (a) create that HashMap in a sciplet in a JSP 
page AND put it into the session THEN (b) submit to an Action and get it back 
out of the session, my answer is "no problem, just do a 
request.getSession().getAttribute("params"); from within the action, you 
don't need to setup anything in your html:form"


On Monday 26 April 2004 03:45 pm, Julia Weaver wrote:
> Thanks for your response.
> What I mean is without use any link on the page, only
> use submit buttons, how can I get parameters? plus the
> page has multiple submit buttons, so I have to use
> LookupDispatchAction.
>
> --- Riyad Kalla <rs...@email.arizona.edu> wrote:
> > I'm not terribly clear on what you are asking...
> > your line:
> > request.getSession(true).setAttribute("params",
> > params);
> >
> > sets the 'params' variable in your session, so your
> > link could actually just
> > be a plan HTML link:
> > <a href="/myapp/GetChildTool.do">Get Tool</a>
> >
> > and your action could still pull params out of your
> > session and process it.
> >
> > Am I missing something?
> >
> > On Monday 26 April 2004 03:10 pm, Julia Weaver
> >
> > wrote:
> > > Hi all,
> > >
> > > Please advise:
> > > I know how to pass params when use <html:link>
> >
> > tag.
> >
> > > But if I want to <html:submit> tag instead, what I
> > > should use to replace: name="params"? Since I
> >
> > cannot
> >
> > > use: <html:submit property="action" name="params"
> >
> > />
> >
> > > This is in my jsp:
> > >
> > > <%
> > > java.util.HashMap params = new
> >
> > java.util.HashMap();
> >
> > > 		params.put("toolId", "thisId");
> > > 		params.put("toolName", "thisName" );
> > > request.getSession(true).setAttribute("params",
> > > params);
> > > %>
> > >
> > > <html:link page="/GetChildTool.do" name= "params"
> > >
> > > 	<bean:write name="tool" property="ToolNbr"/>
> > > </html:link>
> > >
> > >
> > >
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > Yahoo! Photos: High-quality 4x6 digital prints for
> >
> > 25¢
> >
> > > http://photos.yahoo.com/ph/print_splash
>
> ---------------------------------------------------------------------
>
> > > To unsubscribe, e-mail:
> >
> > user-unsubscribe@struts.apache.org
> >
> > > For additional commands, e-mail:
> >
> > user-help@struts.apache.org
>
> ---------------------------------------------------------------------
>
> > To unsubscribe, e-mail:
> > user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> > user-help@struts.apache.org
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Photos: High-quality 4x6 digital prints for 25¢
> http://photos.yahoo.com/ph/print_splash
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: name="params" in ?

Posted by Julia Weaver <dr...@yahoo.com>.
Thanks for your response.
What I mean is without use any link on the page, only
use submit buttons, how can I get parameters? plus the
page has multiple submit buttons, so I have to use
LookupDispatchAction.



--- Riyad Kalla <rs...@email.arizona.edu> wrote:
> I'm not terribly clear on what you are asking...
> your line:
> request.getSession(true).setAttribute("params",
> params);
> 
> sets the 'params' variable in your session, so your
> link could actually just 
> be a plan HTML link:
> <a href="/myapp/GetChildTool.do">Get Tool</a>
> 
> and your action could still pull params out of your
> session and process it.
> 
> Am I missing something?
> 
> On Monday 26 April 2004 03:10 pm, Julia Weaver
> wrote:
> > Hi all,
> >
> > Please advise:
> > I know how to pass params when use <html:link>
> tag.
> > But if I want to <html:submit> tag instead, what I
> > should use to replace: name="params"? Since I
> cannot
> > use: <html:submit property="action" name="params"
> />
> >
> >
> > This is in my jsp:
> >
> > <%
> > java.util.HashMap params = new
> java.util.HashMap();
> > 		params.put("toolId", "thisId");
> > 		params.put("toolName", "thisName" );
> > request.getSession(true).setAttribute("params",
> > params);
> > %>
> >
> > <html:link page="/GetChildTool.do" name= "params"
> >
> > 	<bean:write name="tool" property="ToolNbr"/>
> > </html:link>
> >
> >
> >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Photos: High-quality 4x6 digital prints for
> 25�
> > http://photos.yahoo.com/ph/print_splash
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> user-help@struts.apache.org
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 



	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25�
http://photos.yahoo.com/ph/print_splash

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: name="params" in ?

Posted by Riyad Kalla <rs...@email.arizona.edu>.
I'm not terribly clear on what you are asking... your line:
request.getSession(true).setAttribute("params", params);

sets the 'params' variable in your session, so your link could actually just 
be a plan HTML link:
<a href="/myapp/GetChildTool.do">Get Tool</a>

and your action could still pull params out of your session and process it.

Am I missing something?

On Monday 26 April 2004 03:10 pm, Julia Weaver wrote:
> Hi all,
>
> Please advise:
> I know how to pass params when use <html:link> tag.
> But if I want to <html:submit> tag instead, what I
> should use to replace: name="params"? Since I cannot
> use: <html:submit property="action" name="params" />
>
>
> This is in my jsp:
>
> <%
> java.util.HashMap params = new java.util.HashMap();
> 		params.put("toolId", "thisId");
> 		params.put("toolName", "thisName" );
> request.getSession(true).setAttribute("params",
> params);
> %>
>
> <html:link page="/GetChildTool.do" name= "params" >
> 	<bean:write name="tool" property="ToolNbr"/>
> </html:link>
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Photos: High-quality 4x6 digital prints for 25¢
> http://photos.yahoo.com/ph/print_splash
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org