Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird behavior in Struts2
    text
    copied!<p>I was working on Struts and encountered some strange behavior. Though it is not creating any errors or bugs I just thought it would be interesting to share it with you folks.</p> <p>Perhaps one of you can explain why this is happening.</p> <p>Create a Struts action with following code - </p> <pre><code>public class MyAction extends ActionSupport { private Map&lt;String, Map&lt;String, Object&gt;&gt; map = new HashMap&lt;String, Map&lt;String, Object&gt;&gt;(); public String execute() { System.out.println(map); return SUCCESS; } public Map&lt;String, Map&lt;String, Object&gt;&gt; getMap() { return map; } public void setMap(Map&lt;String, Map&lt;String, Object&gt;&gt; map) { this.map = map; } } </code></pre> <p>Create associated mappings and Jsp required and execute the action. You will see following output on the console - </p> <pre><code>{systemProperties={java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=C:\Program Files\Java\jdk1.6.0_32\jre\bin, java.vm.version=20.7-b02, shared.loader=${catalina.base}/shared/classes .... </code></pre> <p>So apparently Struts is injecting the system properties into my map. But why is it doing so? I didn't ask it to do so. There is no special XML configuration or annotation that I've used. What part of Struts (what interceptor) is responsible for this? Have I just discovered a bug or is this normal behavior? If it's normal why the heck did Struts developer think it'd be wise to inject every <code>Map&lt;String, Map&lt;String, Object&gt;&gt;</code> with system properties?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload