You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jason Deffenbaugh <jd...@techtarget.com> on 2007/11/19 19:56:57 UTC

Using Objects in JSP

In struts 1 you could use the bean:define tag to use objects in a jsp
file... for instance I used this to show a stack trace in an error jsp.

<bean:define name="error" id="e" type="java.lang.Exception"/>
<%
	out.println("<!--");
	StringWriter sw = new StringWriter();
	PrintWriter pw = new PrintWriter(sw);
	e.printStackTrace(pw);
	out.print(sw);

	sw.close();
	pw.close();
	out.println("-->");
%>

where I had set 

catch (Exception e) {
	request.setParameter("error", e);
}

How would I accomplish this in struts 2?

Thanks!

-Jason


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Passing data from one form to another form using hyper link

Posted by Gary Affonso <gl...@greywether.com>.
Zhang, Larry (L.) wrote:
> Say I have page1 (form1) and page2 (form2), on page1 I have a hyper
> link. When I click on the hyperlink, it will call another action (let's
> say action2) which is associated to form2 in the struts-config.xml. My
> question is that how to make form1 data available in action2? Thanks.

This is a classic need for "conversation" scope.  You want to maintain 
data collected on one page over the life of several page requests.

You've got a bunch of options.

1) Do it by hand
Take the data collected on Form 1, store it in some sort of object, put 
that object on the sessions, retrieve that object from the session when 
you execute Action2.

Or, instead of storing it in the session, you can put the data in any 
persistent storage (that lives longer than a single page call) and 
retrieve it in action2.  Some systems use databases to preserve scope 
across page requests instead of the session.

But for what you're doing, I'd bet dollars-to-pesos the session is the 
way to go here.

2) Take a look at the Scope plug-in
This is a plug-in that will basically do what I described above for you 
(using the session for storage) in a more automatic fashion.

3) Take a look at WebFlow and the WebFlow plug-in
This is a tool that cracks the "conversation scope" issue in a variety 
of ways.  Probably overkill for what you want but I thought I'd mention it.

- Gary

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Passing data from one form to another form using hyper link

Posted by "Zhang, Larry (L.)" <lz...@ford.com>.
Say I have page1 (form1) and page2 (form2), on page1 I have a hyper
link. When I click on the hyperlink, it will call another action (let's
say action2) which is associated to form2 in the struts-config.xml. My
question is that how to make form1 data available in action2? Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Using Objects in JSP

Posted by Jason Deffenbaugh <jd...@techtarget.com>.
You're right... why do it in a scriptlet when I can just do it in my
action.  I just used getter/setter and the s:property tag to display my
stack trace string that I created in my catch block.

Thanks!

On Mon, 2007-11-19 at 11:24 -0800, Dave Newton wrote:
> If you want to access something in a scriptlet (which
> hopefully you don't want to do) you can either access
> the value stack or just stick it in one of the scope
> maps. (See ParameterAware, RequestAware, SessionAware,
> ApplicationAware.)
> 
> If you want generic tag-based access then just expose
> the object through the normal S2 mechanism, by
> creating a public getter method; members exposed like
> that are available via both S2 tags and JSTL/JSP EL.
> 
> d.
> 
> --- Jason Deffenbaugh <jd...@techtarget.com>
> wrote:
> 
> > In struts 1 you could use the bean:define tag to use
> > objects in a jsp
> > file... for instance I used this to show a stack
> > trace in an error jsp.
> > 
> > <bean:define name="error" id="e"
> > type="java.lang.Exception"/>
> > <%
> > 	out.println("<!--");
> > 	StringWriter sw = new StringWriter();
> > 	PrintWriter pw = new PrintWriter(sw);
> > 	e.printStackTrace(pw);
> > 	out.print(sw);
> > 
> > 	sw.close();
> > 	pw.close();
> > 	out.println("-->");
> > %>
> > 
> > where I had set 
> > 
> > catch (Exception e) {
> > 	request.setParameter("error", e);
> > }
> > 
> > How would I accomplish this in struts 2?
> > 
> > Thanks!
> > 
> > -Jason
> > 
> > 
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> > user-help@struts.apache.org
> > 
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Using Objects in JSP

Posted by Dave Newton <ne...@yahoo.com>.
If you want to access something in a scriptlet (which
hopefully you don't want to do) you can either access
the value stack or just stick it in one of the scope
maps. (See ParameterAware, RequestAware, SessionAware,
ApplicationAware.)

If you want generic tag-based access then just expose
the object through the normal S2 mechanism, by
creating a public getter method; members exposed like
that are available via both S2 tags and JSTL/JSP EL.

d.

--- Jason Deffenbaugh <jd...@techtarget.com>
wrote:

> In struts 1 you could use the bean:define tag to use
> objects in a jsp
> file... for instance I used this to show a stack
> trace in an error jsp.
> 
> <bean:define name="error" id="e"
> type="java.lang.Exception"/>
> <%
> 	out.println("<!--");
> 	StringWriter sw = new StringWriter();
> 	PrintWriter pw = new PrintWriter(sw);
> 	e.printStackTrace(pw);
> 	out.print(sw);
> 
> 	sw.close();
> 	pw.close();
> 	out.println("-->");
> %>
> 
> where I had set 
> 
> catch (Exception e) {
> 	request.setParameter("error", e);
> }
> 
> How would I accomplish this in struts 2?
> 
> Thanks!
> 
> -Jason
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org