struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Caroline Jen <jiapei_...@yahoo.com>
Subject How To Display the Information That Is Wrapped In a Session Object
Date Sat, 29 Nov 2003 01:54:24 GMT
1. I my action class, I reference a bean 

EditorBean editor = EditorBean.findEditorData(
username );

2. this bean accesses the data access logic and the
bean gets populated by information fetched from the
database (see the code below)

3. In the action class, I then wrap editor in a
session object:

HttpSession session = request.getSession();
editor.setUserrole( request.getParameter( "userrole" )
);
editor.setCategory( request.getParameter( "category" )
);
session.setAttribute( "editor", editor );

4. In the JSP, how do I get userrole and category from
the session object and how to display them in Struts?

Here is my EditorBean class:

public class EditorBean {

   private String username;
   private String userrole;
   private String category;

   // UserDAO and MySQLUserDAO are in another package.
 Must import that package.
   // should not instantiate an interface because it
does not have a constructor
   static EditorDAO ed = new MySQLEditorDAO();

   public EditorBean() {}
   public EditorBean( String username, String
userrole, String category )
   {
      setUsername( username );
      setUserrole( userrole );
      setCategory( category );
   }
   public String getUsername() {
      return username;
   }
   public void setUsername( String username ) {
      this.username = username;
   }
   public String getUserrole() {
      return userrole;
   }
   public void setUserrole( String userrole ) {
      this.userrole = userrole;
   }
   public String getcategory() {
      return category;
   }
   public void setCategory( String category ) {
      this.category = category;
   }
   public static EditorBean findEditorData( String
username ) 
   {
      return ed.findEditor( username );
   } 
}



__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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


Mime
View raw message