Atpakaļ
15. GUI Application
Tālāk
17. Software Project Management

16. exercise: Web Application

Content

General info

  1. Review presentation Java Web Frameworks

      

  2. Investigate package jtm.activity16.
  3. Implement and annotate required main() method of JettyApplication class and teachers(...) method of JettyController class, to create simple web application.
  4. Run JettyApplication class as Java application and check in browser page http://localhost:8080/.
  5. Implement insertTeacher(...), findTeacher(...) and deleteTeacher(...) methods, which:
    1. respond on appropriate web folders of the application,
    2. take passed parameters from the web browser,
    3. call appropriate methods from TeacherManager class in package jtm.activity13 and
    4. sets success or error status of the response and show returned value as HTML.

insertTeacher() requirements

  1. Method responds to /insertTeacher folder
  2. Method takes two optional parameters name and surname
  3. Method calls insertTeacher(String, String) method of TeacherManager class
  4. When no parameters are passed, e.g. http://localhost/insertTeacher, is opened it returns:
    Status: OK (200),
    HTML:

    <form action=''>
    Name: <input type='text' name='name' value=''><br/>
    Surname:<input type='text' name='surname' value=''><br/>
    <input type='submit' value='Insert'></form><br/>
    <a href='/'>Back</a>
  5. When valid parameters are passed, e.g. http://localhost:8080/insertTeacher?name=Tom&surname=Tom, it returns:
    Status: OK
    HTML:

    true<br/>
    <a href='/'>Back</a>
  6. When invalid parameters ar passed, e.g. http://localhost:8080/insertTeacher?name=&surname=, it returns:
    HTTP status: Bad Request (400)

    false<br/>
    <a href='/'>Back</a>

findTeacher() requirements

  1. Method responds to /findTeacher folder
  2. Method takes two optional parameters name and surname
  3. Method calls findTeacher(String, String) method of TeacherManager class
  4. When no parameters are passed, e.g. http://localhost/findTeacher, is opened it returns:
    Status: OK,
    HTML:

    <form action=''>
    Name: <input type='text' name='name' value=''><br/>
    Surname:<input type='text' name='surname' value=''><br/>
    <input type='submit' value='Find'><br/>
    <a href='/'>Back</a>
  5. When parameters are passed, e.g. http://localhost:8080/findTeacher?name=Tom&surname=Tom, it returns:
    Status OK
    HTML:

    <form action=''>
    Name: <input type='text' name='name' value=''><br/>
    Surname:<input type='text' name='surname' value=''><br/>
    <input type='submit' value='Find'><br/>
    <table>
    <tr>
    <td>11</td>
    <td>Tom</td>
    <td>Tom</td>
    </tr>
    </table><br>
    <a href='/'>Back</a>

    where each returned Teacher object is shown in separate row of the table.

deleteTeacher() requirements

  1. Method responds to /deleteTeacher folder
  2. Method takes one optional parameters id
  3. Method calls deleteTeacher(int) method of TeacherManager class
  4. When no parameters are passed, e.g. http://localhost/deleteTeacher, is opened it returns:
    Status: OK,
    HTML:

    <form action=''>
    ID:<input type='text' name='id' value=''><br/>
    <input type='submit' value='Delete'><br/>
    <a href='/'>Back</a>
  5. When valid parameter is passed, e.g. http://localhost:8080/deleteTeacher?id=5, it returns:
    Status: OK
    HTML:

    true<br/>
    <a href='/'>Back</a>
  6. When invalid parameters ar passed, e.g. http://localhost:8080/deleteTeacher?id=1, it returns:
    HTTP status: Bad Request

    false<br/>
    <a href='/'>Back</a>

Additional info

  1. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html
  2. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html
  3. http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html
  4. https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpServletRequest.html
  5. https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpServletResponse.html

Atpakaļ
15. GUI Application
Tālāk
17. Software Project Management
Tagi:
Izveidojis Valdis Vītoliņš 2017-01-03 10:07
Pēdējais mainījis Valdis Vītoliņš 2017-09-14 19:07
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License