<p>I have a JSP page that contains a scriplet where I instantiate an object.  I would like to pass that object to the JSP tag without using any cache.  </p>

<p>For example I would like to accomplish this: </p>

<pre><code>&lt;%@ taglib prefix="wf" uri="JspCustomTag" %&gt;

&lt;% 
 Object myObject = new Object();
%&gt;

&lt;wf:my-tag obj=myObject /&gt;
</code></pre>

<p>I'm trying to avoid directly interacting with any of the caches (page, session, servletcontext), I would rather have my tag handle that.</p>

[{'answer_id': 75745, 'author': 'Brian Matthews', 'author_id': 1969, 'author_profile': 'https://Stackoverflow.com/users/1969', 'pm_score': 0, 'selected': False, 'text': '<p>Use expression language:</p>\n\n<pre>\n    &lt;wf:my-tag obj="${myObject}" /&gt;\n</pre>\n'}, {'answer_id': 75843, 'author': 'Garth Gilmour', 'author_id': 2635682, 'author_profile': 'https://Stackoverflow.com/users/2635682', 'pm_score': 3, 'selected': False, 'text': '<p>The original syntax was to reuse \'&lt;%= %>\'</p>\n\n<p>So</p>\n\n<pre><code>&lt;wf:my-tag obj="&lt;%= myObject %&gt;" /&gt;\n</code></pre>\n\n<p>See <a href="http://java.sun.com/products/jsp/tutorial/TagLibraries16.html#62510" rel="noreferrer">this part of the Sun Tag Library Tutorial</a> for an example</p>\n'}, {'answer_id': 76187, 'author': 'Pavel Feldman', 'author_id': 5507, 'author_profile': 'https://Stackoverflow.com/users/5507', 'pm_score': 2, 'selected': False, 'text': '<p>For me expression language works only if I make that variable accessible, by putting it for example in page context.</p>\n\n<pre><code>&lt;%  Object myObject = new Object();\n    pageContext.setAttribute("myObject", myObject);\n%&gt;\n&lt;wf:my-tag obj="${myObject}" /&gt;\n</code></pre>\n\n<p>Otherwise tas receives null.</p>\n\n<p>And <code>&lt;wf:my-tag obj="&lt;%= myObject %&gt;" /&gt;</code> works with no additional effort. Also &lt;%=%> gives jsp compile-time type validation, while El is validated only in runtime.</p>\n'}, {'answer_id': 355242, 'author': 'Adeel Ansari', 'author_id': 42769, 'author_profile': 'https://Stackoverflow.com/users/42769', 'pm_score': 4, 'selected': False, 'text': '<pre><code>&lt;jsp:useBean id="myObject" class="java.lang.Object" scope="page" /&gt;\n&lt;wf:my-tag obj="${myObject}" /&gt;\n</code></pre>\n\n<p>Its not encouraged to use Scriptlets in JSP page. It kills the purpose of a template language.</p>\n'}, {'answer_id': 1228031, 'author': 'dfrankow', 'author_id': 34935, 'author_profile': 'https://Stackoverflow.com/users/34935', 'pm_score': 5, 'selected': False, 'text': '<p>A slightly different question that I looked for here: "How do you pass an object to a tag file?"</p>\n\n<p>Answer: Use the "type" attribute of the attribute directive:</p>\n\n<pre><code>&lt;%@ attribute name="field" \n              required="true"\n              type="com.mycompany.MyClass" %&gt;\n</code></pre>\n\n<p>The type <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags5.html#wp89854" rel="noreferrer">defaults to java.lang.String</a>, so without it you\'ll get an error if you try to access object fields saying that it can\'t find the field from type String.</p>\n'}, {'answer_id': 27396614, 'author': 'Mike Clark', 'author_id': 4261022, 'author_profile': 'https://Stackoverflow.com/users/4261022', 'pm_score': 1, 'selected': False, 'text': '<p>You can use "&lt;%= %>" to get the object value directly in your tag :</p>\n\n<pre><code>    &lt;wf:my-tag obj="&lt;%= myObject %&gt;"/&gt;\n</code></pre>\n\n<p>and to get the value of any variable within that object you can get that using "obj.parameter" like:</p>\n\n<pre><code>&lt;wf:my-tag obj="&lt;%= myObject.variableName %&gt;"/&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/75626', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13393/']