⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validatemailbean.java

📁 EJB验证邮件地址的示例,feichang de hao.
💻 JAVA
字号:
package com.liudun.ejb;

import java.rmi.RemoteException;

import javax.ejb.SessionBean;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionContext;

/**
 * XDoclet-based session bean.  The class must be declared
 * public according to the EJB specification.
 *
 * To generate the EJB related files to this EJB:
 *		- Add Standard EJB module to XDoclet project properties
 *		- Customize XDoclet configuration for your appserver
 *		- Run XDoclet
 *
 * Below are the xdoclet-related tags needed for this EJB.
 * 
 * @ejb.bean name="ValidateMail"
 *           display-name="Name for ValidateMail"
 *           description="Description for ValidateMail"
 *           jndi-name="ejb/ValidateMail"
 *           type="Stateless"
 *           view-type="remote"
 */
public class ValidateMailBean implements SessionBean {

	public ValidateMailBean() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * An ejbCreate method as required by the EJB specification.
	 * 
	 * The container calls the instance?s <code>ejbCreate</code> method whose
	 * signature matches the signature of the <code>create</code> method invoked
	 * by the client. The input parameters sent from the client are passed to
	 * the <code>ejbCreate</code> method. Each session bean class must have at
	 * least one <code>ejbCreate</code> method. The number and signatures
	 * of a session bean?s <code>create</code> methods are specific to each 
	 * session bean class.
	 * 
	 * @throws CreateException Thrown if method fails due to system-level error.
	 * 
	 * @ejb.create-method
	 * 
	 */
	public void ejbCreate() throws CreateException {
		// TODO Add ejbCreate method implementation
	}

	/**
	 * An example business method
	 *
	 * @ejb.interface-method view-type = "remote"
	 * 
	 * @throws EJBException Thrown if method fails due to system-level error.
	 */
	public void replaceWithRealBusinessMethod() throws EJBException {
		// rename and start putting your business logic here
	}

	@Override
	public void ejbActivate() throws EJBException, RemoteException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void ejbPassivate() throws EJBException, RemoteException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void ejbRemove() throws EJBException, RemoteException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setSessionContext(SessionContext arg0) throws EJBException,
			RemoteException {
		// TODO Auto-generated method stub
		
	}
	
	//得到邮件地址的有效性。
	public boolean validate(String mailAddress) throws RemoteException{
		
		int length=mailAddress.length();
		int potIndex=mailAddress.indexOf(".");
		int atIndex=mailAddress.indexOf("@");
		
		if( !(length>0) ){
			return false;//邮件地址长度不能为0
		}
		
		if( potIndex==-1 || atIndex==-1){
			return false;//.必须存在,并且@必须存在
		}
		if(potIndex<=atIndex || (potIndex+1)==atIndex){
			return false;//.的索引必须大于@索引,并且必须间隔一个以上字符
		}
		if(potIndex>=length){
			return false;//点的索引不能在最后
		}
		return true;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -