Java Server Pages JSP IST 411 Lecture 7

  • Slides: 9
Download presentation
Java. Server Pages (JSP) IST 411 Lecture 7 Spring 2004

Java. Server Pages (JSP) IST 411 Lecture 7 Spring 2004

Java. Server Pages § Java. Server Pages are an extension of servlet technology §

Java. Server Pages § Java. Server Pages are an extension of servlet technology § Simplify the delivery of dynamic Web content § JSPs used when most of the content sent to the client is fixed template data and only a small portion is generated dynamically with Java code

Java. Server Pages § JSPs normally execute as part of a Web server §

Java. Server Pages § JSPs normally execute as part of a Web server § Server is referred to as the JSP container § When first request for a JSP, the JSP container translates it into a Java servlet § Errors compiling the new servlet are translation-time errors

Java. Server Pages § Request / response mechanism and life cycle of a JSP

Java. Server Pages § Request / response mechanism and life cycle of a JSP is the same as that of a servlet § JSPs define jsp. Init and jsp. Destroy which are similar to servlet init and destroy § JSP expressions are delimited by <%= and %> <%= new java. util. Date( ) %> JSP container converts the result of every JSP expression into a String that is output as part of the response

Java. Server Pages § JSPs support 3 comment styles: § JSP comments <%-- and

Java. Server Pages § JSPs support 3 comment styles: § JSP comments <%-- and --%> § XHTML comments <!-- and --> § May not be placed inside scriptlets § Comments from scripting language (Java comments) § // comment § /* and */

Java. Server Pages § Declarations may be made for variables and methods § Variables

Java. Server Pages § Declarations may be made for variables and methods § Variables become instance variable § Use Java syntax <%! int counter = 0; %>

Java. Server Pages § Let’s Practice.

Java. Server Pages § Let’s Practice.

Project 4 § Create a student database with student ID number, name, exam 1

Project 4 § Create a student database with student ID number, name, exam 1 score, and exam 2 score. § Using servlets: § Use a form to enter the data into the database § Retrieve the data and display each student’s average for the course

Project 4 § Will need to use: db. Result = db. Statement. execute. Update(query);

Project 4 § Will need to use: db. Result = db. Statement. execute. Update(query); § Will need to use the SQL command INSERT INTO student (field 1, field 2) VALUES (‘Sue’, ‘Smith’)