And do those files need to be .xml files or could they be .jsp pages?
Main Topics
Browse All TopicsHi Experts,
Is it possible to use a variable definition in the struts-config.xml and tiles-defs.xml file? For example, something like this:
In struts-config.xml:
<action path="/<%=Constants.A_PAGE
And in the tiles-defs.xml, have:
<definition name<%=Constants.A_PAGE%>"
</definition>
I have hundreds of pages in this site, and I am trying to enforce a naming scheme and avoid errors by placing all page names in a Constants file, but I'm not sure if you can do this sort of this with struts. I had this working with regions which used JSP pages as their definition files.
Any hints would be great!
Thanks,
John
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
jsp files MUST have the an extension .jsp
java files MUST have the an extension .java
xml files MUST have the an extension .xml
and you have to put your constants in a java file and name it Constants.java, have "A_PAGE" field defined in that java file and call it in your jsp like you did
<%=Constants.A_PAGE%>"
In another java file, you would call it like this
Constants.A_PAGE
Hi Jaggernaut,
Thanks for your feedback.
I understand all of that, but my question is if there is someway to use a var in the .xml files? Or do I have to use XML files for the tile defs? Otherwise it defeats the purpose of having all the definition names in the Constants file, or at best it is redundant- I have the definitions in two places.
Thanks,
John
you cannot call the java constants in .xml file. It would just not work
Why would it defeat the purpose?
Not really. Even we are using a constants file in our project just like you guys and in all our jsp and java code we are getting the value from the constants file.
In your application, You will have lots of jsp pages and java files but you are going to have just one struts-config.xml file and one tiles-def.xml file. so dont worry about it. It will not be a problem.
Just use the constants in your jsps' and java files.
>>>I have the definitions in two places.
No , just have one and only one constants file for the entire project otherwise you will get confused.
I don't know if this will help you get to what you want. This is taken from an application that a company we subcontract out some work to did, so I'm not sure if any other config options affect this, but I've taken my best guess as to what's relevant. Maybe someone who's more familiar with what this is doing will be able to add comments.
You can reference definitions from the tile-def file within the struts-config file an example of this is shown below. Using this it allows you to define the names in one place, OK I know it's not a constants file, but at least you can reference them from the struts-config file. However, as you can see this doesn't use the tile-def names in the paths which you showed in your question. Is that actually needed as the path names don't have to relate to the jsp file names anyway. Also I'm not sure how you go about referencing these names from jsp, but if you've been working with tile-defs before you may know the answer to that one.
struts-config.xml
<action path="/submitLogin" type="com.classpath.Submit
<forward name="success" path="/mainPage.do">
</forward>
<forward name="failure" path="preLogin.login">
</forward>
</action>
<controller contentType="text/html;cha
<plug-in className="org.apache.stru
<set-property property="definitions-conf
<set-property property="moduleAware" value="true" />
<set-property property="definitions-pars
</plug-in>
tiles-def.xml
<definition id="preLogin.login" name="preLogin.login" path="/layout/siteLayout.j
<put name="section-title" value="Login" />
<put name="page-header" value="/layout/header/head
<put name="side-navigation" value="/layout/leftNav/sid
<put name="mainContent" value="/login.jsp" />
<put name="footer" value="/layout/footer/foot
</definition>
Business Accounts
Answer for Membership
by: jaggernatPosted on 2006-09-15 at 14:29:04ID: 17532836
>>>but I'm not sure if you can do this sort of this with struts
yes, you can do that in struts but not in .xml files like struts-config or tiles-def
You can use something like this <%=Constants.A_PAGE%>" in your jsp and/or java files ,but not xml files.
It will throw an error right away.