aspose file tools*
The moose likes Struts and the fly likes Accessing struts form value in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Accessing struts form value in JSP" Watch "Accessing struts form value in JSP" New topic
Author

Accessing struts form value in JSP

Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
Hi Guys,

Does anyone know how to access a Struts form value in a JSP page? I'm trying to populate Struts property values (businessID & businessName) into a JSP hash map.

Here's my JSP code:

...


</head>

<body>
<html:form action="/searchDetails" name="SearchResultForm" type="org.apache.struts.validator.DynaValidatorForm">

<table width="680" height="246" border="0">
<tr>
<td colspan="2"><bean:write name="SearchResultForm" property="businessID" /></td>
</tr>
<tr>
<td colspan="2"><bean:write name="SearchResultForm" property="businessName" /
</td>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>

<jsp:useBean id="params" class="java.util.HashMap" scope="page" />
<%
params.put("request", request.getAttribute("businessID") );
params.put("businessName", request.getAttribute("businessName") );

%>

...

Please HeLP!!!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Nina,
The form is just an attribute in the request or session. You can do a jsp:useBean or request/session.getAttribute() call and then access the values.

Why do you need a HashMap in the JSP? Usually logic is done in the Action and only presentation is done in the JSP.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
I'm using the Hash map to passed multiple values to the html:link struts tag.

e.g. <html:link name="params" forward="someAction">SomeName</html:html>

I tried using the request.getParameter("businessID"), but it did not work. It is not recognizing the "businessID" form variable I didn't in my struts-config.xml.

Please HeLP!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing struts form value in JSP
 
Similar Threads
finding selected record of nested:iterate using nested:form
Topic: finding selected record of nested:iterate using nested:form
How can I access hidden value from nested:hidden indexed property
Topic: finding selected record of nested:iterate using nested:form
Help me about html:select