Himmat
Himmat

Reputation: 1

display value in jsp page of string using struts2

I'm trying to display value of string using Struts2 in JSP page.

<%String name="Sumit"; %>
Name: <s:property value="name"/>

But it doesn't display anything.

Upvotes: 0

Views: 4240

Answers (2)

kvista
kvista

Reputation: 5059

A few comments/suggestions:

1) To elaborate a bit on what BalusC said, the scriptlet you wrote (i.e., <% String name="submit"; %> is separate from the reference to an action property (i.e., )

2) Typically, what people do is they write an action class and associate it with a particular URL in their struts2.xml. So let's say you do this and write an action called MyAction. When you call reference in a JSP, you're really calling "getName()" on an instance of the "MyAction" class. Presumably, you will follow the command pattern of action classes and construct a useful value for name in the execute() method of your Action class.

3) Scriptlets that define local Java values can indeed be useful during JSP processing (I find they are helpful whenever I'm integrating with non Struts2 frameworks like DisplayTagg), but they have nothing to do with the action. You're simply setting some temporary Java variable to a value. When you use it, you need to de-reference it in scriptlet style (e.g., <%= name %>, etc)

Upvotes: 0

BalusC
BalusC

Reputation: 1108547

Scriptlets and taglibs doesn't share the same variable scope. Use the one or the other, not both.

Upvotes: 2

Related Questions