18. Web application
| Prev | Next |
Review the presentation Java Web Frameworks
Tasks
- Fulfill the requirements of insertStudent()
- Fulfill the requirements of findStudent()
- Meet the requirements of deleteStudent()
- Run Unit Tests
- Additional Information
Add execute permissions to the geckodriver library1:
cd ~/workspace/JTM/lib
chmod +x geckodriver- If necessary, change the server.port=8800 value in the .../src/main/resources/application.properties file to a different port number, such as 8801, according to the number assigned to you.
- Explore the package jtm.activity18.
- Implement and annotate the required main() method of the JettyApplication class and the ...Student(...) method of the JettyController class to create a simple web application.
- Run the JettyApplication class as a Java application and log in to the browser page http://localhost:8800/.
- Implement the methods insertStudent(...), findStudent(...), and deleteStudent(...) that:
- respond to the appropriate web folders of the application,
- take the parameters passed from the web browser,
- call the appropriate methods of the StudentManager class in the package jtm.activity13, and
- set the response to success or failure and display the return value as HTML.
Fulfill the requirements of insertStudent()
- The method responds to the folder /insertStudent
- The method takes two optional parameters name and surname
- The method references the StudentManager class method insertStudent(String, String)
When no parameters are passed, e.g. http://localhost:8800/insertStudent 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>When valid parameters are passed, e.g. http://localhost:8800/insertStudent?name=Tom&surname=Tom, it returns:
Status: OK
HTML:true<br/>
<a href='/'>Back</a>If invalid parameters are passed, e.g. http://localhost:8800/insertStudent?name=&surname=, it returns:
HTTP status: Bad Request (400)false<br/>
<a href='/'>Back</a>
Fulfill the requirements of findStudent()
- The method responds to the folder /findStudent
- The method takes two optional parameters name and surname
- The method calls the StudentManager class method findStudent(String, String)
When no parameters are passed, e.g. http://localhost:8800/findStudent, opens, 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'></form><br/>
<a href='/'>Back</a>When parameters are passed, e.g. http://localhost:8800/findStudent?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'></form><br/>
<table>
<tr>
<td>11</td>
<td>Tom</td>
<td>Tom</td>
</tr>
</table><br>
<a href='/'>Back</a>where each returned Student object is displayed in a separate table row.
Meet the requirements of deleteStudent()
- The method responds to the folder /deleteStudent
- The method requires one optional parameter id
- The method calls the deleteStudent(int) method of the StudentManager class
When no parameters are passed, e.g. http://localhost:8800/deleteStudent, is opened, it returns:
Status: OK,
HTML:<form action=''>
ID: <input type='text' name='id' value=''><br/>
<input type='submit' value='Delete'></form><br/>
<a href='/'>Back</a>When a valid parameter is passed, e.g. http://localhost:8800/deleteStudent?id=5, it returns:
Status: OK
HTML:true<br/>
<a href='/'>Back</a>When invalid parameters are passed, e.g. http://localhost:8800/deleteStudent?id=1, it returns:
HTTP status: Bad Requestfalse<br/>
<a href='/'>Back</a>
Run Unit Tests
- JettyApplicationTest.java is a unit test that tests the web application using API calls.
- SeleniumWebDriverTest.java is a web GUI test that tests the web application by emulating user actions in the Firefox browser.
Additional Information
For Implementation:
- http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html
- http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html
- http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/ResponseBody.html
- https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpServletRequest.html
- https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpServletResponse.html
For API testing:
GUI for testing:
| Prev | Next |
- ^ When the project is extracted from the *.zip file, the execute property is lost for all files. Therefore, the SeleniumWebDriverTests execute permissions. Java file must be restored because Selenium tests require them.


