O GoConqr está de visual novo! Conte para nós o que você achou.

Mapa mental

Java Enterprise

Usuário eliminado O usuário eliminou as informações de disciplina Inglês

Java Enterprise

Conteúdo do mapa

Java Enterprise

  1. Spring MVC

    • in java classes
      • @Controller
        • @Autowired
          • set the service name
          • @RequestMapping (path="/pathname", method = RequestMethod.POST / RequestMEthod.GET)
            • @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;
            • ask autowired service to do something
              • servicename.method();
              • ModelAndView mv = new ModelAndView("jsp location");
      • @Service
        • pass action to JPA or JDBC, get result / throw exception
    • import springframework
    • in JSP
      • <%@ taglib prefix="c" uri="java.sun.com....."
        • <c:if test="${error != null}">
        • <c: forEach var="st" items="${studentlist}">
  2. Server/Client

    • Socket programming
      • Basic serversocket
        • Server side
          • &nbsp;&nbsp; import java.io.IOException; import java.net.ServerSocket; &nbsp; public class Server { &nbsp; &nbsp; public static void main(String[] args) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; ServerSocket server = null; &nbsp; &nbsp; &nbsp; &nbsp; try &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;server = new ServerSocket(5000);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; catch(IOException e)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
          • while(true) { &nbsp; &nbsp; try &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; Socket socket = server.accept(); &nbsp; &nbsp; &nbsp; &nbsp; InputStream is = socket.getInputStream(); &nbsp; &nbsp; &nbsp; &nbsp; StringBuffer mesg = new StringBuffer(); &nbsp; &nbsp; &nbsp; &nbsp; while(true) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int data = is.read(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (data == -1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mesg.append((char)data); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(mesg); &nbsp;&nbsp; &nbsp; } &nbsp; &nbsp; catch(IOException e) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace(); &nbsp; &nbsp; } }
          • use socket.getInputStream
          • use socket = server.accept();
          • open server by ServerSocket(5000)
          • decode by StringBuffer
          • is.read();
        • Client side
          • import java.io.IOException; import java.io.OutputStream; import &nbsp;java.net.Socket; &nbsp; public class Client { &nbsp; &nbsp; public static void main(String[] args) &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; try &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Socket client = new Socket("localhost",5000); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OutputStream os = client.getOutputStream(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os.write("Hello ISCG7425".getBytes());&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; os.close(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; client.close(); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; catch(IOException e) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace(); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } }
          • socket client = new socket("localhost",5000);
          • client.getOutputStream
          • os.write("msg".getbytes());
          • os.close();
        • Data Streams
          • 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) { &nbsp; break; } &nbsp;}&nbsp;
          • 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();&nbsp;
          • use DataInputStream/DataOutputStream
          • dis = new DataInputStream(socket.getInputStream());
          • dos = new DataOutputStream(socket.getOutputStream());
          • dis.readUTF();
          • dos.writeUTF("msg");
      • Server Threads
        • final &nbsp;Socket socket &nbsp;= server.accept(); Thread &nbsp;serverThread = new Thread() { public &nbsp;void run() { &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InputStream is = socket.getInputStream(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StringBuffer mesg = new StringBuffer(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while(true) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int data = is.read(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(data == -1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mesg.append((char)data); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(this.getName() + "\n"+ mesg); &nbsp; }catch(IOException e) { /* … Handle exceptions … / } } }; serverThread.start();
        • Thread serverThread = new Thread(){the server activities}
        • serverTread.start();
        • should include thread.sleep(1000) method
    • Servlets and JSP
      • http
        • text-base protocol for hypertext (HTML)
        • 20+ years old
        • becomes popular and extended to send other type of data
        • simple to implement
        • request-respond kind of protocol, only client can request
      • Servlets
        • help developer focus on business rules
        • providing resources to handle incoming request and outgoing responds
        • need mapping with html url-pattern
        • can be done by annotations: @WebServlet("/weblocation")
      • JSP
        • JavaServerPages
        • need not to transfer java to html
        • translated to Servlets
        • using <% jave coding %> format to inport code to webpage
        • can directly use some variables:request / response / out / session / application
  3. Database connection

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

Imagens e arquivos do mapa

  • Java Enterprise
  • Java Enterprise

Informações

Descrição
O usuário eliminou as informações de disciplina Mapa Mental sobre Java Enterprise, criado por Usuário eliminado em 23-08-2017.
Criado por
Usuário eliminado · ago 2017
Atualizado
23 ago 2017
Visualizações
18
Histórico
  • Criado por hon sam Chan · 18 jun 2016
  • Copiado por Павел Караваев · 23 ago 2017
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?