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 Spring in Action this week in the Spring 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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

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!
 
 
subject: Accessing struts form value in JSP