Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to pass parameter in struts ?

 
harish pathak
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Anybody please tell me how to pass parameter in struts as we pass
parameter in jsp/servlet as ?name=name&sex=sex

Thanks

harish
 
Rob Morning
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Save it in the session usingsomething like

session.setAttribute("USER",user);
session.setAtttribute("SEX",sex);

in your JSP ..

Is that what you mean ?
 
harish pathak
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no i mean like in our jsp we do like this so how we do in struts.

<%
String s =" harish";

%>

<a href="/abc.jsp?name=<%=s%>">click here</a>



How can we pass parameters in struts


Thanks

harish
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The equivalent of your example using struts tags would be:

<bean:define id="userName" value="Harish"/>
<a href='/abc.jsp?name=<bean:write name="userName" />'>click here</a>
[ January 07, 2006: Message edited by: Merrill Higginson ]
 
shahin Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pass it in the similar manner as you pass in jsp.Are you facing any problems with this if so plz let me know
 
Thierry Collogne
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you pass your parameter like this



You can use the following to retreive




I hope this helps.

Thierry
 
Thierry Collogne
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, little mistake



is wrong. This needs to be



The paramName is the value, as it is in the pagecontext, you want to pass and paramId is the name of the parameter.
 
Vikrama Sanjeeva
Ranch Hand
Posts: 760
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Make a FormBean (ActionForm) of the JSP from where you are passintg the value and declare getter/setter of the variable which is holding your value.

For "?name=abc&sex=male" define a form bean which have getter/setter for name and sex variables.

In the action, retrieved the values of name and sex using form's getter method.

E.g:


Hope it will helps.

Bye,
Viki.
 
Yugesh Cc
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Craeting the bean with setters and getters works fine , but if we use this approach only those value can be obtained which are there in form (e.g.text boxes etc).But what should i do if i want to pass some additional parameters thru that JSp page.
I wish to use hidden variables for this but when i try to assign value to a hidden variable then it gives error as bellow
"According to TLD, tag html:hidden must be empty, but is not"

How can i use hidden variables in struts then
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Yugesh Cc:

I wish to use hidden variables for this but when i try to assign value to a hidden variable then it gives error as bellow
"According to TLD, tag html:hidden must be empty, but is not"


Please post your html:hidden code block. Read this first and see if it helps:
http://struts.apache.org/1.2.7/userGuide/struts-html.html#hidden
 
netto gaurav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i also have the same problem
i have an list of records on one column i have the edit image which when clicked opens the record for editing now I'm not getting how to pass the value to the action class and how to get the values of the telephone at the action

the code is below:



please reply its urgent
 
Pawan Singh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the solution by my own
you just have to set the object in pagecontext.setattribute(String arg0, Object arg1)
then <html:link action="......" paramid="XXX" paramName="String arg0"/>

you can retrieve this parameter in your action class as :
request.getParameter("XXX"/paramid);


here in code view:


<%String mail=sf.getEmailid();
pageContext.setAttribute("emailid",mail);%>

<html:link action="/information" onfocus="focus()" paramId="mailid" paramName="emailid" scope="request"><font color="#00FF00">

<%= sf.getEmailid() %></font></html:link></td>
<%}%>



here sf.getEmailid() is a String type Object which i have to pass as a parameter from a jsp to action class in link form.
hope you like this , and definetly it will work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic