How does your FindEditorData class get called? It is the responsibility of
the caller to tell this class who the user is. I assume that there is an
Action mixed in here since the call is made in response to an HTML form
being submitted. Have your Action figure out who the user is
(request.getRemoteUser()) and then pass that information along to your
FindEditorData class.

Don't trust a hidden field to tell you who the user is. You will get hacked.

-Max

----- Original Message ----- 
From: "Caroline Jen" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Saturday, December 06, 2003 4:02 PM
Subject: RE: Very Troubled in Finding Ways to Pass a Variable to a Class


> It is wonderful to know that there are some ActionForm
> methods that holds true in the
> scaffold.ProcessAction's execute() method.  It gives
> the hope that my problem could be resolved.
>
> Via a submit button in my JSP, I try to pass two
> variables; username and keyName, to my Java class
> (FindEditorData.java) with the
> type="org.apache.struts.scaffold.ProcessAction", and
> this Java class has this method:
>
>    public Object execute() throws Exception { ... }
>
> 1. if I use the hidden field technique (see below)
> inside the JSP <html:form ....> tag:
> <% String username = request.getRemoteUser();%>
> <html:hidden property="username"
>              value="<%=username%>"/>
> <html:hidden property="keyName"
>              value="journal_category"/>
>
> How do I retrieve the value of username and keyName in
> the Java class?  Probably due to my lack of knowledge
> of the ActionForm, I got compilation error "cannot
> resolve symbol: request" or "cannot resolve symbol:
> session" because FindEditorData.java does not extend
> HttpServlet and FindEditorData.java does not extend
> Action.
>
> 2. if I want to get 'username' in the Java class
> instead of passing the 'username' as a hidden field
> from a submit button in my JSP, how do I do it?
>
> String username = request.getRemoteUser(); gives me a
> compilation error "cannot resolve symbol: request".
>
> The action mapping in my struts-config.xml looks like:
>     <action
>         roles="editor"
>         path="/find/Category"
>
> type="org.apache.struts.scaffold.ProcessAction"
>
> parameter="org.apache.artimus.article.FindEditorData"
>         name="articleForm"
>         scope="request"
>         validate="false">
>        <forward
>             name="success"
>             path=".article.Result"/>
>     </action>
>
> -Caroline
> --- Joe Hertz <[EMAIL PROTECTED]> wrote:
> > Actually, you haven't illustrated it. You've just
> > stated it.
> >
> > In the ActionForm there are methods like validate()
> > that accept as
> > parameters an ActionMapping and an
> > httpServletRequest, and from the
> > httpServletRequest you can call getSession().
> >
> > Same holds true in the Action class' execute()
> > method.
> >
> > So what is the problem with your class? Why can't
> > you utilize it from
> > one of these places that you do have access to these
> > things? What
> > exactly is stopping you here? Once you tell us, then
> > you will have
> > illustrated the problem.
> >
> > -J
> >
> > > -----Original Message-----
> > > From: Caroline Jen [mailto:[EMAIL PROTECTED]
> > > Sent: Saturday, December 06, 2003 1:47 PM
> > > To: Struts Users Mailing List
> > > Subject: Re: Very Troubled in Finding Ways to Pass
> > a Variable
> > > to a Class
> > >
> > >
> > > 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 <[EMAIL PROTECTED]> 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" <[EMAIL PROTECTED]>
> > > > To: <[EMAIL PROTECTED]>
> > > > 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:
> > > > [EMAIL PROTECTED]
> > > > > For additional commands, e-mail:
> > > > [EMAIL PROTECTED]
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > >
> >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > > > For additional commands, e-mail:
> > > > [EMAIL PROTECTED]
> > > >
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > New Yahoo! Photos - easier uploading and sharing.
> > http://photos.yahoo.com/
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >
> >
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >
>
>
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to