Java Enterprise

Description

Mind Map on Java Enterprise, created by hon sam Chan on 18/06/2016.
hon sam Chan
Mind Map by hon sam Chan, updated more than 1 year ago
hon sam Chan
Created by hon sam Chan over 8 years ago
11
0

Resource summary

Java Enterprise
  1. Spring MVC
    1. in java classes
      1. @Controller
        1. @Autowired
          1. set the service name
            1. @RequestMapping (path="/pathname", method = RequestMethod.POST / RequestMEthod.GET)

              Annotations:

              • @RequestMapping(      path = "/add", method = RequestMethod.POST) public ModelAndView addstudent( @RequestParam("name") String name, @RequestParam("email") String email, @RequestParam("dob") String dob) { try { addStudentService.addstudent(name, email, dob);  ModelAndView mv = new ModelAndView("addstudent"); String added = "Student Added!"; mv.addObject("added", added);   return mv; } catch (Exception ex) { ModelAndView mv = new ModelAndView("addstudent"); mv.addObject("error", ex.getMessage());   return mv;
              1. ask autowired service to do something
                1. servicename.method();
                  1. ModelAndView mv = new ModelAndView("jsp location");
            2. @Service
              1. pass action to JPA or JDBC, get result / throw exception
            3. import springframework
              1. in JSP
                1. <%@ taglib prefix="c" uri="java.sun.com....."
                  1. <c:if test="${error != null}">
                    1. <c: forEach var="st" items="${studentlist}">
                2. Server/Client
                  1. Socket programming
                    1. Basic serversocket
                      1. Server side

                        Annotations:

                        •    import java.io.IOException; import java.net.ServerSocket;   public class Server {     public static void main(String[] args)     {         ServerSocket server = null;         try         {          server = new ServerSocket(5000);        }        catch(IOException e)        {            e.printStackTrace();        }    }}
                        • while(true) {     try     {         Socket socket = server.accept();         InputStream is = socket.getInputStream();         StringBuffer mesg = new StringBuffer();         while(true)         {             int data = is.read();             if (data == -1)             {                 break;             }             else           {                mesg.append((char)data);            }        System.out.println(mesg);      }     catch(IOException e)     {         e.printStackTrace();     } }
                        1. use socket.getInputStream
                          1. use socket = server.accept();
                            1. open server by ServerSocket(5000)
                              1. decode by StringBuffer
                                1. is.read();
                                2. Client side

                                  Annotations:

                                  • import java.io.IOException; import java.io.OutputStream; import  java.net.Socket;   public class Client {     public static void main(String[] args)     {         try         {             Socket client = new Socket("localhost",5000);            OutputStream os = client.getOutputStream();             os.write("Hello ISCG7425".getBytes());              os.close();             client.close();         }         catch(IOException e)         {             e.printStackTrace();         }     } }
                                  1. socket client = new socket("localhost",5000);
                                    1. client.getOutputStream
                                      1. os.write("msg".getbytes());
                                        1. os.close();
                                        2. Data Streams

                                          Annotations:

                                          • Socket socket = server.accept(); DataInputStream dis = new DataInputStream(socket.getInputStream()); DataOutputStream dos = new DataOutputStream(socket.getOutputStream()); while(true) { try { String mesg = dis.readUTF(); dos.writeUTF("Echo response:"+mesg); } catch(EOFException e) {   break; }  } 
                                          • Socket client = new Socket("localhost",5000); DataOutputStream dos = new DataOutputStream(client.getOutputStream()); DataInputStream dis = new DataInputStream(client.getInputStream()); dos.writeUTF("Test Message"); String resp = dis.readUTF(); System.out.println(resp); client.close(); 
                                          1. use DataInputStream/DataOutputStream
                                            1. dis = new DataInputStream(socket.getInputStream());
                                              1. dos = new DataOutputStream(socket.getOutputStream());
                                                1. dis.readUTF();
                                                  1. dos.writeUTF("msg");
                                                2. Server Threads

                                                  Annotations:

                                                  • final  Socket socket  = server.accept(); Thread  serverThread = new Thread() { public  void run() {   try {             InputStream is = socket.getInputStream();             StringBuffer mesg = new StringBuffer();             while(true) {                 int data = is.read();                 if(data == -1)                     break;                else                     mesg.append((char)data);             }             System.out.println(this.getName() + "\n"+ mesg);   }catch(IOException e) { /* … Handle exceptions … / } } }; serverThread.start();
                                                  1. Thread serverThread = new Thread(){the server activities}
                                                    1. serverTread.start();
                                                      1. should include thread.sleep(1000) method
                                                    2. Servlets and JSP
                                                      1. http
                                                        1. text-base protocol for hypertext (HTML)
                                                          1. 20+ years old
                                                            1. becomes popular and extended to send other type of data
                                                              1. simple to implement
                                                                1. request-respond kind of protocol, only client can request
                                                                2. Servlets
                                                                  1. help developer focus on business rules
                                                                    1. providing resources to handle incoming request and outgoing responds
                                                                        1. need mapping with html url-pattern
                                                                          1. can be done by annotations: @WebServlet("/weblocation")
                                                                          2. JSP
                                                                            1. JavaServerPages
                                                                              1. need not to transfer java to html
                                                                                1. translated to Servlets
                                                                                  1. using <% jave coding %> format to inport code to webpage
                                                                                    1. can directly use some variables:request / response / out / session / application
                                                                                  2. Database connection
                                                                                    1. JDBC

                                                                                      Annotations:

                                                                                      • JDBCDataSource ds =  new JDBCDataSource(); // setup  URL according to HSQLDB specs ds.setUrl("jdbc:hsqldb:hsql://localhost/contacts"); // set  other data source properties ds.setPassword(""); ds.setUser("SA"); // setup  global database connection  conn = ds.getConnection();  
                                                                                      1. interface to allow java to access SQL database
                                                                                        1. use Classes and Factory method
                                                                                          1. Driver based model
                                                                                            1. basic setup: port, hostname, schema, database name
                                                                                              1. set JDBCDataSource ds --> setUrl & password & username --> getConnection()
                                                                                                1. conn = DriverManager.getconnnection(url,username,password)
                                                                                                  1. PreparedStatement stmt = conn.prepareStatement("SQL Code")
                                                                                                    1. stmt.setData(value,value);
                                                                                                      1. stmt.executeUpdate();
                                                                                                        1. stmt.close(); conn.close();
                                                                                                    2. Statement stmt = conn.createStatement();
                                                                                                      1. ResultSet rs = stmt.executeQuery("SQL code");
                                                                                                        1. String name = rs.getString("name");
                                                                                                          1. rs.close(); stmt.close(); conn.close();
                                                                                                      2. one conn, many stmt, each stmt one rs
                                                                                                    3. JPA
                                                                                                      1. Java Persistence Architecture
                                                                                                        1. EntityManager em = factory.createEntityManager();
                                                                                                          1. em.setFlushMode(FlushModeType.COMMIT);
                                                                                                            1. em.getTransaction().begin();
                                                                                                              1. em.createQuery("SELECT u FROM User As u").getResultList();
                                                                                                                1. em.getTransaction().commit();
                                                                                                                  1. factory.close();
                                                                                                          2. set local dataset item by id
                                                                                                            1. @Entity / @Table(name = "table name in database"

                                                                                                              Annotations:

                                                                                                              • for mapping
                                                                                                              1. @ID
                                                                                                                1. setName / getName
                                                                                                            Show full summary Hide full summary

                                                                                                            Similar

                                                                                                            Atoms and Reactions
                                                                                                            siobhan.quirk
                                                                                                            Physics 2a + 2b
                                                                                                            James Squibb
                                                                                                            Tectonic Hazards flashcards
                                                                                                            katiehumphrey
                                                                                                            Electromagnetism: Magnetic Flux Density & Magnetic Flux 2
                                                                                                            tatemae.honne
                                                                                                            Databases
                                                                                                            Dean Whittle
                                                                                                            Key Biology Definitions/Terms
                                                                                                            mia.rigby
                                                                                                            The Biological basis of Heart Disease
                                                                                                            Andrea Leyden
                                                                                                            Longevidad y Envejecimiento Fisiológico
                                                                                                            Isaac Alexander
                                                                                                            RadioTelefonia
                                                                                                            Adriana Forero
                                                                                                            The Periodic Table
                                                                                                            asramanathan
                                                                                                            OP doplnovaci otazky II.
                                                                                                            Helen Phamova