This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing struts form value in JSP

 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic