0

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.

1
  • You need to provide more info. Commented Dec 30, 2010 at 8:26

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.