Download presentation
Presentation is loading. Please wait.
1
j4www/jea Week 3 Version 2.3.2009Slide 1j.c.westlake@staffs.ac.uk, edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models Multiple JSPs to handle a request. JSPs calling other JSPs i.e. breaking up work JSPs with Update SQL examples Designing for JSPs Summary JSP models
2
j4www/jea Week 3 Version 2.3.2009Slide 2j.c.westlake@staffs.ac.uk, edits: nas1 Multiple JSPs Last week we introduced the two forms of the include tag. Action - for dynamic content (although it can handle static content too) Directive - for static content For this module we are particularly interested in the dynamic capabilities of the include action tag The directive version is still useful, but it is not as powerful
3
j4www/jea Week 3 Version 2.3.2009Slide 3j.c.westlake@staffs.ac.uk, edits: nas1 Include directive in an JSP Including Text From Another File Welcome Open Day Students Hope You Enjoy The Day
4
j4www/jea Week 3 Version 2.3.2009Slide 4j.c.westlake@staffs.ac.uk, edits: nas1 Include directive result
5
j4www/jea Week 3 Version 2.3.2009Slide 5j.c.westlake@staffs.ac.uk, edits: nas1 Include action – very useful Why are we more interested in the action tag? The directive version is only used for static documents like template JSP, HTML or images. The include action treats the included file as a dynamic document - it includes the output of the included file instead of including the code – this is interesting! We can now think about JSPs working together – the web engineering concept of modular code or referred to as component software.
6
j4www/jea Week 3 Version 2.3.2009Slide 6j.c.westlake@staffs.ac.uk, edits: nas1 The include action - why? Spreads out the work of an application (design implication – see later slides). The example we will now show illustrates this: It contains an HTML form for user entry of requests passes them on to a primary JSP which is responsible for the request and generating the response the primary JSP uses the values received from the HTML form to select the appropriate “worker” JSP to run (two JSPs we have already seen). The model is depicted on the next slide.
7
j4www/jea Week 3 Version 2.3.2009Slide 7j.c.westlake@staffs.ac.uk, edits: nas1 Include action model Primary JSP JSPs Client Request and Response DATABASE Include model The JSP parses the input from the HTML form and includes the appropriate JSP to service the client request The included JSPs are translated into their Servlet code, compiled and then executed - it is the output of that execution that is inserted into the output of the primary JSP HTTP Server - Tomcat HTML Form SQL
8
Using Guestbook Data HTML form with multiple JSPs to run <FORM NAME="DataSelection" ACTION="http://server etc:8080/includeguestbookexample.jsp" METHOD="POST"> List JSP Get JSP Call to the Primary JSP important
9
example of the include action - used to include the output of another JSP <% Enumeration params = request.getParameterNames(); while (params.hasMoreElements()) { String inputName = (String)params.nextElement(); String inputValue = request.getParameter(inputName); if (inputValue.equals("list")) { System.out.println('\n' + inputValue); //output the value %> <% } else if (inputValue.equals("search")){ %> <% } // end else clause } // end while loop %> Worker JSP includeguestbookexample.jsp
10
j4www/jea Week 3 Version 2.3.2009Slide 10j.c.westlake@staffs.ac.uk, edits: nas1 So…… The primary JSP includes the “output” of other “worker” JSPs In this example a sort of menu has been achieved It is the primary JSP’s role to accept the request from the user and generate a response to the user which can be done by using the include action There is no limit to the number of JSPs which can be used - nice scalable solution - separating out work! - if a new feature/menu item is needed - just add another JSP There are some issues about the work organisation however and we will discuss this later in the module when we look at the MVC concept
11
j4www/jea Week 3 Version 2.3.2009Slide 11j.c.westlake@staffs.ac.uk, edits: nas1 The update problem How to tackle this problem? What do we need to do? Design some steps Understand the SQL we can use Solution using the Guests example We need to: Allow the user to select a guest record Let the user view it Allow the user to modify it and then write it back to the database i.e. update it Are there any aspects we don’t wish to allow the user to do? Yes – they cannot alter the primary key
12
j4www/jea Week 3 Version 2.3.2009Slide 12j.c.westlake@staffs.ac.uk, edits: nas1 The update solution So…….we need ….. A form that can call a jsp which simply displays the result from the fetch in a set of text boxes rather than a table format – this allow the user to do something with the data (those who are new to HTML will need to think about this) We can then allow the user to: change the content of the text box for firstname and then call a jsp to do the update to the database and then call another jsp to display the confirmation or return to our starting point
13
j4www/jea Week 3 Version 2.3.2009Slide 13j.c.westlake@staffs.ac.uk, edits: nas1 UPDATE SQL A JSP which can use the parameters from the update form and call a JSP to update the database Use the Update SQL command
14
j4www/jea Week 3 Version 2.3.2009Slide 14j.c.westlake@staffs.ac.uk, edits: nas1 Demo of update Now follows http://fcet11:8080/nas1/examples/updateGuests.html We have put the code in a zip file linked into the schedule Copy the HTML, 2 JSPs and a DB into your folder and modify the connection string to the access the database Let us run it and then have a look at the code
15
j4www/jea Week 3 Version 2.3.2009Slide 15j.c.westlake@staffs.ac.uk, edits: nas1 Assignment context You can use the same approach to modify and update something in the database For example an FAQ... You now have from the opening 3 weeks of the module How to CRU How to add (create) something How to view something (retrieve) How to change something (update)
16
j4www/jea Week 3 Version 2.3.2009Slide 16j.c.westlake@staffs.ac.uk, edits: nas1 Summary You have seen an update example This type of web design starts to look like a service oriented architecture (SOA), JSPs that will service other JSPs or HTML forms given the appropriate information
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.