How to get JAVA_OPTS value in jsp
I am trying to get JAVA_OPTS value defined in catalina.bat in a jsp file. Can someone tell me how to do that.
For Example: My JAVA_OPTS definition in catalina.bat is like
JAVA_OPS= -DMyProjectHome=D:\Pro开发者_如何学编程jects
I want to have the value of MyProjectHome at run time in jsp file so I am trying to do is ${MyProjectHome} but it is doing nothing.
Or is there a way I can define JAVA_OPTS value in
Please help me out achieving my functionality.
thanks.
what you pass to a JVM with -Dfoo=bar is called a system property. You can get their value using System.getProperty(). There is no standard tag or JSP EL syntax to get them, though, so you'll have to use scriptlet or implement a custom tag.
Wrap it in a class which extends a Map.
public class SystemProperties extends HashMap<String, String> {
    @Override
    public String get(Object name) {
        return System.getProperty(name != null ? name.toString() : null);
    }
}
Declare it as follows in JSP.
<jsp:useBean id="systemProperties" class="com.example.SystemProperties" scope="application" />
Then you can just treat it as Map in EL.
${systemProperties['MyProjectHome']}
or
${systemProperties.MyProjectHome}
Those are Java system properties. You can access it via the Java function
System.getProperty("MyProjectHome");
There might be a better way to do it in JSP but that will work.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论