You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Caroline Jen <ji...@yahoo.com> on 2003/12/06 05:17:06 UTC
Very Troubled in Finding Ways to Pass a Variable to a Class
I have a class FindEditorData.java. I want to pass a
vairable 'username' to this class for some processing.
This class is invoked from a JSP:
<html:form action="/find/Category">
<html:submit>View Articles</html:submit>
and the value of the 'username' is obtained this way:
String username = request.getRemoteUser();
Due to my limited knowledge in Struts, I cannot
figure out what to do. Let me explain the problem:
1. This class has this method:
public Object execute() throws Exception { ... }
I do not make this class extends HttpServlet or
extends Action. I cannot nest a method inside a
doGet/doPost or the Action's excute().
2. The action mapping in the struts-config.xml is this
way:
<action
roles="editor"
path="/find/Category"
type="org.apache.struts.scaffold.ProcessAction"
parameter="org.XYZ.article.FindEditorData"
name="articleForm"
validate="false">
<forward
name="success"
path=".article.Result"/>
</action>
I am stuck because I do not know how to pass
'username' to the FindEditorData.java. I cannot
state:
String username = request.getRemoteUser();
or
String username = (String)session.getAttribute(
"EditorName" );
because the FindEditorData is not a servlet and
does not extend Action.
I cannot pass a hidden variable from the JSP because I
do not know how to retrieve the value of a hidden
variable in a Java class.
Need clever ideas. Please help.
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Very Troubled in Finding Ways to Pass a Variable to a Class
Posted by Caroline Jen <ji...@yahoo.com>.
I know how to pass a hidden field. The problem is how
to retrieve it in my Java class. I have illustrated
that my Java class does not extend HttpServlet or
Action.
This Java class has a mapping in the struts-config.xml
file:
type="org.apache.struts.scaffold.ProcessAction"
parameter="org.XYZ.article.FindEditorData"
name="articleForm"
-Caroline
--- Timo <ti...@telus.net> wrote:
> Caroline,
> The best way I use it to pass parameters to the
> action class is via a hidden
> attribute in the form, in your case the
> "articleForm"
> you can define the hidden attribute using
>
> <input type="hidden" name="hiddenField"
> value="<%=request.getRemoteUser();%>"/>
> Good luck.
>
> ----- Original Message -----
> From: "Caroline Jen" <ji...@yahoo.com>
> To: <st...@jakarta.apache.org>
> Sent: Friday, December 05, 2003 8:17 PM
> Subject: Very Troubled in Finding Ways to Pass a
> Variable to a Class
>
>
> > I have a class FindEditorData.java. I want to
> pass a
> > vairable 'username' to this class for some
> processing.
> > This class is invoked from a JSP:
> >
> > <html:form action="/find/Category">
> > <html:submit>View Articles</html:submit>
> >
> > and the value of the 'username' is obtained this
> way:
> >
> > String username = request.getRemoteUser();
> >
> > Due to my limited knowledge in Struts, I cannot
> > figure out what to do. Let me explain the
> problem:
> >
> > 1. This class has this method:
> >
> > public Object execute() throws Exception { ...
> }
> >
> > I do not make this class extends HttpServlet or
> > extends Action. I cannot nest a method inside a
> > doGet/doPost or the Action's excute().
> >
> > 2. The action mapping in the struts-config.xml is
> this
> > way:
> > <action
> > roles="editor"
> > path="/find/Category"
> >
> > type="org.apache.struts.scaffold.ProcessAction"
> > parameter="org.XYZ.article.FindEditorData"
> > name="articleForm"
> > validate="false">
> > <forward
> > name="success"
> > path=".article.Result"/>
> > </action>
> >
> > I am stuck because I do not know how to pass
> > 'username' to the FindEditorData.java. I cannot
> > state:
> >
> > String username = request.getRemoteUser();
> > or
> > String username = (String)session.getAttribute(
> > "EditorName" );
> >
> > because the FindEditorData is not a servlet and
> > does not extend Action.
> >
> > I cannot pass a hidden variable from the JSP
> because I
> > do not know how to retrieve the value of a hidden
> > variable in a Java class.
> >
> > Need clever ideas. Please help.
> >
> >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > New Yahoo! Photos - easier uploading and sharing.
> > http://photos.yahoo.com/
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> >
> >
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Very Troubled in Finding Ways to Pass a Variable to a Class
Posted by Timo <ti...@telus.net>.
Caroline,
The best way I use it to pass parameters to the action class is via a hidden
attribute in the form, in your case the "articleForm"
you can define the hidden attribute using
<input type="hidden" name="hiddenField"
value="<%=request.getRemoteUser();%>"/>
Good luck.
----- Original Message -----
From: "Caroline Jen" <ji...@yahoo.com>
To: <st...@jakarta.apache.org>
Sent: Friday, December 05, 2003 8:17 PM
Subject: Very Troubled in Finding Ways to Pass a Variable to a Class
> I have a class FindEditorData.java. I want to pass a
> vairable 'username' to this class for some processing.
> This class is invoked from a JSP:
>
> <html:form action="/find/Category">
> <html:submit>View Articles</html:submit>
>
> and the value of the 'username' is obtained this way:
>
> String username = request.getRemoteUser();
>
> Due to my limited knowledge in Struts, I cannot
> figure out what to do. Let me explain the problem:
>
> 1. This class has this method:
>
> public Object execute() throws Exception { ... }
>
> I do not make this class extends HttpServlet or
> extends Action. I cannot nest a method inside a
> doGet/doPost or the Action's excute().
>
> 2. The action mapping in the struts-config.xml is this
> way:
> <action
> roles="editor"
> path="/find/Category"
>
> type="org.apache.struts.scaffold.ProcessAction"
> parameter="org.XYZ.article.FindEditorData"
> name="articleForm"
> validate="false">
> <forward
> name="success"
> path=".article.Result"/>
> </action>
>
> I am stuck because I do not know how to pass
> 'username' to the FindEditorData.java. I cannot
> state:
>
> String username = request.getRemoteUser();
> or
> String username = (String)session.getAttribute(
> "EditorName" );
>
> because the FindEditorData is not a servlet and
> does not extend Action.
>
> I cannot pass a hidden variable from the JSP because I
> do not know how to retrieve the value of a hidden
> variable in a Java class.
>
> Need clever ideas. Please help.
>
>
>
>
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org