user67722
user67722

Reputation: 3277

How to get value from struts bean?

I am new to struts. I'm just trying to build a simple application that gets the input from the user and display it. For which I got the input from the user and stored it in a bean and I have also displayed it in the next page using bean:write but how to place it in a text box. I tried to use html:text but I don't know how to place the value in it.

Thanks in advance

Upvotes: 2

Views: 8285

Answers (4)

masshi
masshi

Reputation:

You can use "" to directly get the value of the property from the bean. Ex:

<bean:write name="user" property="username" />
Replace by this:
<html:text name="user" property="username" style="width:150" maxlength="20"/>

In that:
name - is the bean object name
property - is the property of the bean object

Good luck!

Upvotes: 0

user29891
user29891

Reputation: 13

If you want to place that in a text box I think you might want to try textfield tag

Upvotes: 0

Bhushan Bhangale
Bhushan Bhangale

Reputation: 10987

You need to wrap html:text with html:form. The action attribute of html:form will point to an action defined in struts-config.xml. This action will be associated with a form bean where you have stored the value you are talking about. Then in html:text refer to that property like this

<html:text property="property name where the value is stored"/>

Upvotes: 0

Snehal
Snehal

Reputation: 7496

Set the property or bean that you want to display in the request attribute and fetch the value from it in the final page:

The syntax for inserting a value in text box is

<html:text property="propertyName" value="value"></html:text/>

Upvotes: 2

Related Questions