FileDocCategorySizeDatePackage
CheckLogonTag.javaAPI DocExample3559Tue Jul 27 06:01:18 BST 2004org.apache.struts.webapp.example

CheckLogonTag

public final class CheckLogonTag extends javax.servlet.jsp.tagext.TagSupport
Check for a valid User logged on in the current session. If there is no such user, forward control to the logon page.
version
$Revision: 1.11 $ $Date: 2004/03/13 05:23:39 $

Fields Summary
private String
name
The key of the session-scope bean we look for.
private static String
LOGIN_PATH
Path to use if a login is needed.
private String
page
The action to which we should forward for the user to log on.
Constructors Summary
Methods Summary
public intdoEndTag()
Perform our logged-in user check by looking for the existence of a session scope bean under the specified name. If this bean is not present, control is forwarded to the specified logon page.

exception
JspException if a JSP exception has occurred

    
    	// Is there a valid user logged on?
    	boolean valid = false;
    	HttpSession session = pageContext.getSession();
    	if ((session != null) && (session.getAttribute(name) != null)) {
    	    valid = true;
        }
    
        // Forward control based on the results
        if (valid) {
            return (EVAL_PAGE);
        } else {
            ModuleConfig config =
                (ModuleConfig) pageContext.getServletContext().getAttribute(
                    org.apache.struts.Globals.MODULE_KEY);
            
                try {
                    pageContext.forward(config.getPrefix() + page);
                } catch (ServletException e) {
                    throw new JspException(e.toString());
                } catch (IOException e) {
                    throw new JspException(e.toString());
                }
             
            return (SKIP_PAGE);
        }
    
    
public intdoStartTag()
Defer our checking until the end of this tag is encountered.

exception
JspException if a JSP exception has occurred



    // ------------------------------------------------------- Public Methods


                            
         

	   return (SKIP_BODY);

    
public voidrelease()
Release any acquired resources.


        super.release();
        this.name = Constants.USER_KEY;
        this.page = LOGIN_PATH;