File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Very Troubled In Finding Ways To Pass A Variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Very Troubled In Finding Ways To Pass A Variable" Watch "Very Troubled In Finding Ways To Pass A Variable" New topic
Author

Very Troubled In Finding Ways To Pass A Variable

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
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 this way:

and the value of the 'username' is obtained this way:

Due to my limited knowledge in Struts, I cannot figure out what to do. Let me explain the problem:
1. There is this method inside the FindEditorData.java:

Therefore, 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 declared this way:

I am stuck because I do not know how to pass 'username' to the FindEditorData.java. I cannot state:

because the FindEditorData is not a servlet and does not extend Action. The compiler will give me "cannot resolve symbol: request/session"
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.
[ December 05, 2003: Message edited by: JiaPei Jen ]
[ December 05, 2003: Message edited by: JiaPei Jen ]
David Yutzy
tumbleweed and gunslinger
Ranch Hand

Joined: Jun 29, 2001
Posts: 192
I would have your page post to a standard Action servlet, then create an instance of your class from there.
At that point, you have access to the request object (passed into the method via the Struts framework) and can pass the value to your class.
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
There is a difficulty to make this class a regular servlet because there is this method inside the FindEditorData.java:

Therefore, 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().
 
 
subject: Very Troubled In Finding Ways To Pass A Variable
 
Similar Threads
How To Create This Drop-Down List
Unable To Pass A Hidden Field To scaffold.ProcessAction
Pass A String and Write Out Its Value in JSP
Struggling With Passing Data Between Data Access Class, Business Bean, and Controller
Where Do I Create Session, Set Attribute, etc. In Struts?