JAVA EE (brief)

Source: Internet
Author: User
Tags java se

I. Overview of the Platform

The full name of Java EE is Edition, a specification and standard for developing distributed enterprise-class applications.

Three versions of the Java platform:

    • Java ME (Java micro Edition) Java mini-version
    • Java SE (Java standard Edition) Java Standards Edition
    • Java EE (Java Enterprise Edition) Java Business Edition
II. Overview of the architecture

Java EE server:

Java EE server provides deployment, management, and operational support for standards-compliant application components

Depending on the Java EE server, the application components can be divided into 3 classes.

    • Deploy, manage, and run components on a Java EE server. (Web Components and EJB components)
    • Deploy and manage components that are running on a Java EE server, but are loaded into the client. (Web resources for HTML pages and applets that embed pages)
    • Deploy and manage components that are not fully defined in the Java EE specification. (Application client)

Iii. Overview of containers

Containers provide a running environment for Java EE application components.

The container provides a federated view from the underlying Java EE API to the application components.

Adding a container between the application component and the Java EE service allows the container to transparently inject the necessary services into the component.

A standard Java EE product provides a container for each application component type.

Container Overview:

A container is a collection of tools used to manage the behavior of a component, including interactions with the external environment, the lifecycle of components, cooperative dependencies between components, and so on.

Java EE container:
    • Application Client Container: Contains component application client
    • Applet container: Contains component applets
    • Web Component container: Contains JSP and servlet components
    • Enterprise Bean Container: The EJB container that contains the EJB components
Iv. Services

Overview: A service is an interface between a component and a container, and between a container and a Java EE server

V. Common Services

Jndi Get Data source

<ResourceAuth= "Container"Driverclassname= "Oracle.jdbc.OracleDriver"maxactive= "+"Maxidle= "+"Maxwaite= "10000"name= "Jdbc/jndi"Password= "ACCP"type= "Javax.sql.DataSource"URL= "Jdbc:oracle:thin: @localhost: 1521:orcl"username= "ACCP" />
/*** Get connections via Jndi*/     PublicConnection getconnection () {Connection conn=NULL; Try {            //declaring context ObjectsContext ct=NewInitialContext (); //declaring a data sourceDataSource ds= (DataSource) ct.lookup ("Java:comp/env/jdbc/jndi"); //Get Connectedconn=ds.getconnection (); } Catch(namingexception e) {e.printstacktrace (); } Catch(SQLException e) {e.printstacktrace (); }        returnConn; }
Mail
 Packagecom;Importjava.util.Properties;Importjavax.mail.Address;ImportJavax.mail.BodyPart;ImportJavax.mail.Message;ImportJavax.mail.Multipart;Importjavax.mail.Session;ImportJavax.mail.Transport;Importjavax.mail.internet.InternetAddress;ImportJavax.mail.internet.MimeBodyPart;ImportJavax.mail.internet.MimeMessage;ImportJavax.mail.internet.MimeMultipart;/*** Send mail **/ Public classMail {PrivateMimeMessage mimemsg; PrivateSession session; PrivateProperties props; PrivateString username; PrivateString password; PrivateMultipart MP;  PublicMail (String smtp) {setsmtphost (SMTP);    Createmimemessage (); }         Public voidsetsmtphost (String hostName) {System.out.println ("Set System Properties: mail.smtp.host=" +hostName); if(props==NULL) {Props=system.getproperties (); } props.put ("Mail.smtp.host", HostName); }         Public BooleanCreatemimemessage () {Try{System.out.println ("Ready to get mail Session Object!" "); Session= Session.getdefaultinstance (Props,NULL); }Catch(Exception e) {System.out.println ("An error occurred while getting mail session Object!" "+e); return false; } System.out.println ("Ready to create a MIME mail Object!" "); Try{mimemsg=NewMimeMessage (session); MP=NewMimemultipart (); return true; }Catch(Exception e) {System.out.println ("Failed to create MIME message Object!" "+e); return false; }    }    /*** Set whether SMTP requires authentication*/       Public voidSetneedauth (Booleanneed) {System.out.println ("Set SMTP authentication: Mail.smtp.auth =" +need); if(Props = =NULL) props =system.getproperties (); if(need) {Props.put ("Mail.smtp.auth", "true"); }Else{props.put ("Mail.smtp.auth", "false"); }        }         Public voidSetnamepass (String name,string pass) {username=name; Password=Pass; }         /*** Set Message subject*/       Public BooleanSetsubject (String mailsubject) {System.out.println ("Set the message subject!" "); Try{mimemsg.setsubject (mailsubject); return true; }            Catch(Exception e) {System.err.println ("There was an error setting the message subject!" "); return false; }        }              /*** Set message body*/         Public Booleansetbody (String mailbody) {Try{bodypart bp=NewMimeBodyPart (); Bp.setcontent ("" +mailbody, "TEXT/HTML;CHARSET=GBK");                           Mp.addbodypart (BP); return true; } Catch(Exception e) {System.err.println ("An error occurred while setting the message body!" "+e); return false; }        }                   /*** Set Sender*/         Public BooleanSetfrom (String from) {System.out.println ("Set the sender!" "); Try{Mimemsg.setfrom (NewInternetAddress (from));//Set Sender            return true; } Catch(Exception e) {return false; }        }        /*** Set up the recipient.*/         Public BooleanSetto (String to) {if(To = =NULL)return false; System.out.println ("Set up the recipient!" he said. "); Try{mimemsg.setrecipients (Message.recipienttype.to,internetaddress.parse (to)); return true; } Catch(Exception e) {return false; }          }               /*** Set cc person*/         Public BooleanSetcopyto (String copyto) {if(CopyTo = =NULL)return false; Try{mimemsg.setrecipients (Message.RecipientType.CC, (address[]) Internetaddress.parse (CopyTo)); return true; }            Catch(Exception e) {return false; } }               /*** Send mail*/         Public Booleansendout () {Try{mimemsg.setcontent (MP);                Mimemsg.savechanges (); System.out.println ("Sending mail ...."); Session mailsession= Session.getinstance (Props,NULL); Transport Transport= Mailsession.gettransport ("SMTP"); Transport.connect (String) props.get ("Mail.smtp.host"), Username,password);                             Transport.sendmessage (Mimemsg,mimemsg.getrecipients (Message.RecipientType.TO)); System.out.println ("Send mail success!" ");                               Transport.close (); return true; } Catch(Exception e) {System.err.println ("Mail sent failed!" "+e); return false; }        }               /*** Call sendout method to complete mail sending*/       Public Static BooleanSENDANDCC (String smtp,string from,string to,string copyto,string subject,string content,string username,String Password) {Mail Themail=NewMail (SMTP); Themail.setneedauth (true);//need to verify                   if(!themail.setsubject (subject))return false; if(!themail.setbody (content))return false; if(!themail.setto (To))return false; if(!themail.setcopyto (CopyTo))return false; if(!themail.setfrom (from))return false;                   Themail.setnamepass (Username,password); if(!themail.sendout ())return false; return true; }   }

JAVA EE (brief)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.