You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Daniel PC Leung <pc...@gmail.com> on 2005/02/24 02:39:49 UTC

How to get attribute of Form from Controller class?

The following class extends Tiles Controller class.
After user logins, it cannot get the value of login username from the
class LoginForm. How can I change the code so that it can get the
value of login username?

Thnx


	  public void perform (ComponentContext context,
	                       HttpServletRequest request,
	                       HttpServletResponse response,
	                       ServletContext servletContext)
	                throws ServletException, IOException {

	  	HttpSession session = request.getSession();
	  	session.getAttribute("loginForm.username");

	  }

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


RE: How to get attribute of Form from Controller class?

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Daniel,

>From what you'd written, it looks like you're thinking of JSP 2.0 where the
JSP could use $loginForm.username to retrieve the value of the username
field from the session object loginForm.  So, I believe you want something
more like so:

LoginForm loginForm = (LoginForm) session.getAttribute("loginForm");
String username = loginForm.getUsername();

Of course, it depends on the getXXX method in your LoginForm class AND the
exact name you saved the ActionForm to in the Session scope.

Regards,
David

P.S. I'm suddenly thinking you might have been serious with your first post
about the "Nada" software joke. *very scared*

-----Original Message-----
From: Daniel PC Leung [mailto:pc.leung@gmail.com]
Sent: Wednesday, February 23, 2005 8:40 PM
To: Struts Users Mailing List
Subject: How to get attribute of Form from Controller class?


The following class extends Tiles Controller class.
After user logins, it cannot get the value of login username from the
class LoginForm. How can I change the code so that it can get the
value of login username?

Thnx


	  public void perform (ComponentContext context,
	                       HttpServletRequest request,
	                       HttpServletResponse response,
	                       ServletContext servletContext)
	                throws ServletException, IOException {

	  	HttpSession session = request.getSession();
	  	session.getAttribute("loginForm.username");

	  }

---------------------------------------------------------------------
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