Java Enterprise

Beschreibung

Mindmap am Java Enterprise, erstellt von hon sam Chan am 18/06/2016.
hon sam Chan
Mindmap von hon sam Chan, aktualisiert more than 1 year ago
hon sam Chan
Erstellt von hon sam Chan vor mehr als 8 Jahre
11
0

Zusammenfassung der Ressource

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)

              Anmerkungen:

              • @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

                        Anmerkungen:

                        •    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

                                  Anmerkungen:

                                  • 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

                                          Anmerkungen:

                                          • 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

                                                  Anmerkungen:

                                                  • 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

                                                                                      Anmerkungen:

                                                                                      • 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"

                                                                                                              Anmerkungen:

                                                                                                              • for mapping
                                                                                                              1. @ID
                                                                                                                1. setName / getName
                                                                                                            Zusammenfassung anzeigen Zusammenfassung ausblenden

                                                                                                            ähnlicher Inhalt

                                                                                                            04_Kommanditgesellschaft
                                                                                                            Stefan Kurtenbach
                                                                                                            Gemischte Klausur- und sonstige Fragen
                                                                                                            Bibische
                                                                                                            Nathan der Weise - Zusammenfassung
                                                                                                            Laura Overhoff
                                                                                                            Einführung in das wissenschaftliche Arbeiten
                                                                                                            Flo Ma
                                                                                                            FOST 3 - Inferenzstatistik
                                                                                                            Kathy H
                                                                                                            PuKW - GESKO PR
                                                                                                            Elisa Kosch
                                                                                                            FOLO (PuKW STEOP B)
                                                                                                            Lara Gundacker
                                                                                                            Parasitologie 2019
                                                                                                            Peter Christian Ponn
                                                                                                            Chirurgie 2014 Vetie
                                                                                                            Kim Langner
                                                                                                            Vetie Geflügelkrankheiten Fragebogen 3
                                                                                                            Annika G
                                                                                                            Vetie - Spezielle Pathologie 2021
                                                                                                            Valerie Nymphe