FileDocCategorySizeDatePackage
CheckLogonTag.javaAPI DocExample6379Sun Mar 07 19:48:42 GMT 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.
author
Craig R. McClanahan
author
Marius Barduta
version
$Revision: 1.8 $ $Date: 2003/04/09 02:28:24 $

Fields Summary
private String
name
The key of the session-scope bean we look for.
private String
page
The page 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


	   return (SKIP_BODY);

    
public java.lang.StringgetName()
Return the bean name.



    // ----------------------------------------------------------- Properties


             
       

	   return (this.name);

    
public java.lang.StringgetPage()
Return the forward page.


	   return (this.page);

    
public voidrelease()
Release any acquired resources.


        super.release();
        this.name = Constants.USER_KEY;
        this.page = "/logon.jsp";

    
public voidsetName(java.lang.String name)
Set the bean name.

param
name The new bean name


	   this.name = name;

    
public voidsetPage(java.lang.String page)
Set the forward page.

param
page The new forward page


	   this.page = page;