aspose 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
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().
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Very Troubled In Finding Ways To Pass A Variable