0

We are using strusts2+spring3.2+struts.spring.plugin Also we are using the property place holder to access the properties in actions

Something like:

@Value("${web.site.name}") private String siteName; 

And we have siteName ready and populated.

Is it possible that we can access the value in the JSP pages too? Or we should first get it from struts action and then pass it to JSP.

Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173

1 Answers1

0

Probably you can't. But if you can, you shouldn't... You should pass the value using controller. One way to use the property directly in the jsp is to write custom tag that reads the property file and choose the one that you need.

Example(not tested):

public class TemplateTag extends SimpleTagSupport{

    private String propName;//add setter to get it from the tag attribute

    public void doTag()throws JspException, IOException{
        JspWriter out = getJspContext().getOut();
        Properties prop = new Properties();
                prop.load(new FileInputStream("config.properties"));


        out.print(prop.getProperty(propName));
    }

As Aleksandr M suggested you can use the built in tags: http://www.mkyong.com/struts/struts-internationalizing-or-localization-example/

Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145