SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Servers - Apache Tomcat Server Server-side scripts - Java Server Pages Java Server Pages - Xue Bai
Objectives  What is  Request/Response  protocol for a  client-side  script   What is  Request/Response  protocol for  server-side  script  How does server interact with  multiple concurrent clients   How can html  meta-tag s control request/response interaction  How does effect depend on file  extension  - html versus jsp
I:  client-side, server-side, .jsp, JavaScript form screening,  JSP results, multi-threaded server responses, Html meta-tag refresh, need for .jsp  versus .html extension, JSP’s conditional generation of Html, forms,  buttons, onClick event, JavaScript function, reset, role of names on forms  to identify form elements, table definition, textfields, alert pop-up window, configuring for Apache Tomcat server, Class & ClassPath  system environment variables, <script & <% tags for JavaScript & JSP II:  form - events - extend form, yjspapphapter02example14.html, qualified names for elements, submitting form data, request/response cycle[38], GET method:processing by server-side program, submit button, method identification, how element names are used, how JSP program accesses form element values, run: chapter03xample6a.html example - note query string sent to server - in address field of browser - after submit clicked - un-highlight beforehand so visible, focus attention, request.getParameter method, JSP Html dynamic output, dynamic html example: 12a  http://localhost:8080/myapp/chapter03/example6a.html http://localhost:8080/myapp/chapter03/example10a.jsp - contrast Netscape & IE http://localhost:8080/myapp/chapter03/example12a.html  & 12b Topics
client 1. requests URL for html page server 2. retrieves  html page 3. sends html page to client 4. browser interprets html page & displays Typical html  Request/Response  cycle
Request/Response for page -  JavaScript  commands client 1. requests URL for html page server 2. retrieves  html page 3. responds w. page to client 4. interprets page -  (browser) executes Java script commands  eg: check for bad or missing data on form with embedded JavaScript commands CLIENT-SIDE SCRIPT (Apache Tomcat)
4. interprets page -  Request/Response for page - with  JavaScript  commands executes Java script Commands  client server 3. sends page to client 1. requests page 2. gets page
1 - requests  JSP page server 2 - retrieves page 3 - responds with html+results in page browser executes  server-side script may have embedded JSP server script & Java-client-Script Request/Response for file with Java Server Page   parts SERVER-SIDE SCRIPT
Request/Response for Java Server Page client 1. sends URL  for  JSP  page server 2.  retrieves  page from storage 3. sends html  + results to client 4. browser  displays page  executes  JSP code replaces  code with exec results *   compiled first time only - thereafter uses compiled copy experiment on effect  of  extensions like .jsp or .html compiles  embedded JSP code  *
2 - retrieves page using URL addr &  server configuration 1 - requests  JSP page server 3 - responds & html + results  browser executes  client-side script executes  server-side script http://localhost:8080 /myapp /chapter02/example2a.html Context path= &quot; /myapp &quot; docBase= &quot;c:yjspapp&quot; http://localhost:8080/ c:yjspapp hapter02xample2a.html
Experiment:  JSP versus JavaScript - client v. server execution 1.  Start Apache Tomcat server  listening on port 8080 localhost  2.  Request a  Java Server page  from server - source file  will have Results   3.  Request  html page  with JavaScript - source page  will have the   JavaScript   [at least in Explorer - not Netscape] 2.  C:yjspapphapter01xample2. jsp 3.  C:yjspapphapter02xample2a. html – prev slide Start Tomcat server from start Menu or shortcut on desktop
<html> <head>  <title> current server time </title>  </head> <font face = &quot;Arial&quot;  size =4> The current Date and time on the web server are: <BR> <%= new  java.util.Date() %> </font> </body> </html> Request  for  JSP .jsp  page  retrieved is: embedded  jsp instruction jsp instruction - executed  on &quot;server-side&quot; - result replaces code C:yjspapphapter01xample2. jsp
1.  Request this page from server which is Listening on port 8080 2.  Contents sent by server -  after executing jsp code located in requested file
<html> <head>  <title> current server time </title>  </head> <font face = &quot;Arial&quot;  size =4> The current Date and time on the web server are: <BR> Wed Nov 27 20:27:02 EST 2002 </font> </body> </html> 1.  &quot; source &quot;  as shown in browser 2. Note how Date’s  Result replaces original JSP in page sent to browser
sent to  browser and executed  on browser requested source page is same as displayed in browser Request for Java Script page <HTML> <HEAD> <TITLE>Client-side  script </TITLE></HEAD> <BODY> THE TIME ON THE CLIENT IS:  Current time is: <%= new  java.util.Date( ) %> <script language=&quot;JavaScript&quot; > document.write (new Date() ) </script> </BODY> </HTML> C:yjspapphapter02xample2a .html Request from server - versus drag-and-drop in browser - observe address bar Why not executed  on server ?
JavaScript Request  response displayed in browser Source shows only JavaScript code  - not the computed date
How can a server interface with multiple client browsers simultaneously ? Ans:  creates multiple threads - one per browser. Experiment:  JSP with refresh meta-tag from multiple browsers  Use  URL:  http://localhost:8080/myapp/chapter02/ example12.jsp Source contains  Html Meta tag : < META   HTTP-EQUIV = &quot;REFRESH&quot; CONTENT = &quot;5, URL=example12.jsp&quot;> and  JSP instruction :  <%= new java.util.Date() %>
<HTML> <HEAD>  <TITLE>  server-side scripts  </TITLE>  < META   HTTP-EQUIV = &quot;REFRESH&quot; CONTENT = &quot;5, URL=example12.jsp&quot;> </HEAD> <BODY> The time on the server is: <%= new java.util.Date( ) %>  </BODY> </HTML> JSP page requested is: requested  every 5 sec from current directory of  original   request JSP  result  replaces this code & is sent to browser URL:  http://localhost:8080/myapp/chapter02/ example12.jsp
IP address  of server port that server  listens on Requested  File’s  address on the server remainder of file address path server uses  configuration file to convert this to initial part of path: &quot;http://localhost: helloWorld.js 8080  /myapp/  WHERE WHICH WHAT C:yjspapp
What happens if you request an html page that has embedded JSP  ?
-- effect of EXTension on how server handles request: Effect of suffix:  http://localhost:8080/myapp/chapter01/project3. html  versus http://localhost:8080/myapp/chapter01/project3. jsp Source html contains Java Server Page instructions - java inside jsp tags:  <%  ...  %>  <% java.util.Calendar  calendar  = java.util.Calendar.getInstance( ); int  hour  =  calendar .get(calendar.HOUR_OF_DAY); if (  hour <12)   { %> <h3>Good morning!</h3> <% } else { %> <h3>Good afternoon!</h3> <% } %> JSP ...it would be better to just use print statement – this looks confusing.
<HTML> <HEAD><TITLE>Welcome to JSP</TITLE></HEAD> <BODY> <% java.util.Calendar calendar = java.util.Calendar.getInstance(); int  hour  = calendar.get(calendar.HOUR_OF_DAY); if (  hour  < 12) { %> Hour is <br> <%= hour  %> <h3>Good morning!</h3> <%}else {%> <h3>Good afternoon!</h3> <%}%> </BODY> </HTML> project3. jsp  versus  same  file with  different  extension:   project3. html HTML –  green JSP –  red  /  blue JSP  starts/stops with  <% … %> Html   can occur anywhere else
Page displayed for project3. jsp : Good afternoon! Welcome to Introduction to JSP In this chapter, you: learned about Web client/server architecture  learned the difference between static and dynamic Web pages  learned how dynamic Web pages are generated in JSP  reviewed various server-side processing technologies  compared JSP to alternate  time-dependent jsp output
Displayed page  For project3 . html IE  browser - no result (and no JSP shown) Good morning! Good afternoon! Welcome to Introduction to JSP In this chapter, you: learned about Web client/server architecture  learned the difference between static and dynamic Web pages  learned how dynamic Web pages are generated in JSP  reviewed various server-side processing technologies  compared JSP to alternate technologies
Netscape  - no result (JSP shown) <% java.util.Calendar calendar = java.util.Calendar.getInstance(); int hour = calendar.get(calendar.HOUR_OF_DAY); if( hour<12){%>  Good morning! <%} else {%>  Good afternoon! <%}%>  Welcome to Introduction to JSP In this chapter, you: learned about Web client/server architecture  learned the difference between static and dynamic Web pages  learned how dynamic Web pages are generated in JSP  reviewed various server-side processing technologies  compared JSP to alternate technologies  Displayed page  project3 . html
Java Server Pages - II
How does  request/response protocol  operate for forms & jsp pages  How do you  submit  form data to server using  GET  method?  Objectives - Understand How to  configure  a (Tomcat) server   How do you  dynamically  construct Html using Java Server Pages  What is the  URL  format  How do JSP programs  get data  from  forms
How do you  submit  form data to server using  GET  method? C:yjspapphapter03xample6a.html C:yjspapphapter03etUserInfo.jsp
Experiment :  demonstrates submitting and retrieving  form data using GET method 1.  chapter03/example6a.html  sends data via  GET ,[object Object],[object Object],[object Object]
Request/Response protocol 2.  retrieve html form  browser 4.  display form  - user enters data &  submits  form 6.  triggers retrieving, compiling getUserInfo.jsp referred to on form  - executes jsp with data  from query-string  1.  request html page  example6a.html 3.  returns form  7.  returns results  to client 5.  sends URL +query-string chapter03xample6a.html server understand thoroughly
<HTML> <HEAD> <TITLE>  Submit using GET Method  </TITLE> </HEAD> <BODY>  <H1> Please sign </H1> <form name = &quot;formName&quot; ACTION = &quot; getUserInfo.jsp &quot;  Method =&quot; GET &quot; > Your Name:  <input type=text  name=  firstName   size=24 > <br> Your Major:  <input type=text  name=  major   size=24 > <br> <input type= submit  value=&quot;submit&quot;  > <input type=reset  value=&quot;Clear Form&quot;  > </form> THE TIME ON THE CLIENT IS:  <script language=&quot;JavaScript&quot; > document.write (new Date( ) ) </script> </BODY> </HTML> example6a.html jsp program executed  on Submit triggers submission of query string to server GET sends data in query-string data names
Query string   sent by browser to server: http://localhost:8080/ myapp/chapter03/getUserInfo.jsp ?  firstName=aaa&major=zzz jsp to execute data for program SERVER PROGRAM DATA FOR PROGRAM WHERE WHO WHAT
<HTML> <HEAD> <TITLE>  get User information  </TITLE> </HEAD> <BODY> <H1> Hi there - how are you?  </H1> Your major is:   <%=  request.getParameter(&quot;major&quot;)  %>   <br> Your name is:  <%=  request.getParameter(&quot;firstName&quot;)  %>   <br> <br> The current Date and time on the web server are: <BR> <%= new  java.util.Date() %> <br> </BODY> </HTML> getUserInfo.jsp  retrieves values entered on form which are returned in query string field names on html form that triggered execution of getUserInfo.jsp
<HTML> <HEAD> <TITLE>  get User information  </TITLE> </HEAD> <BODY> <H1> Hi there - how are you?  </H1> Your major is:  <%=  request.getParameter(&quot; major &quot;)  %>   <br> Your name is:  <%=  request.getParameter(&quot; firstName &quot;)  %>   <br> <br> The current Date and time on the web server are: <BR> <%= new  java.util.Date() %> <br> </BODY> </HTML> getUserInfo.jsp  http://localhost:8080/ myapp/chapter03/getUserInfo.jsp ?  firstName =aaa& major =zzz DATA FOR PROGRAM
C:yjspapp hapter01ilename http://localhost:8080/ myapp /chapter01/filename so file retrieved is: replaced with  C:/myjspapp because of  server configuration Requested file on server Server IP Interpretation  of URL  port The context prefix  myapp  makes the web site Relocateable. You just change  myapp  to point to the directory where site pages begin.
How do you  configure the Tomcat server  ?
Environment setup  1. control panel > system > advanced  > environment variables >  system variables %SystemRoot%ystem32;%SystemRoot%; %SystemRoot%ystem32bem; C:dk1.2.2in ...on one line points to JDK bin update  PATH  variable to include JDK 2. similarly  add CLASSPATH  system variable  defined as :  C:dk1.2.2reibt.jar; .; C:rogram Filespache Tomcat 4.0ommonibervlet.jar; C:yjspappEB-INFLASSES … all on a single line Assumes jdk 1.2.2  -- same idea for other versions of jdk.
Environment setup  1. start > all programs > Apache Tomcat 4.0 >  Edit Configuration file right after:  <!-- Tomcat Root Context --> <!-- <Context path=&quot;&quot; docBase=&quot;ROOT&quot; debug=&quot;0&quot;/> --> add: <Context path= &quot;/myapp&quot; docBase= &quot;c:yjspapp&quot; debug=&quot;0&quot; reloadable=&quot;true&quot; /> http://localhost:8080/ myapp /chapter01/filename 1. this 2. gets expanded  to  this
Environment setup  1. start > all programs > Apache Tomcat 4.0 > Edit Configuration file add: <Context path= &quot;/myapp&quot; docBase= &quot;c:yjspapp&quot; debug=&quot;0&quot; reloadable=&quot;true&quot; /> http://localhost:8080 /myapp/chapter03/example6.html If user wants:  C:yjspapphapter03xample6.html then asks for:
What are the advantages of using a client-side versus server-side script ? Client-side script can prevent bad data being sent to server which would waste  user’s time, server’s time, and  waste communication resources Server-side script allows  protected  server-side access to data on the server side.
<HTML> <HEAD> <TITLE>  jsp output  </TITLE> </HEAD> <BODY> <%=  &quot;<font  size =6 color = red> Hello </font>&quot;  %> <br><br> <font  size =4 color = blue> How are you? </font> <br><br> <%  out.println ( &quot;<font  size = 8 color = green> Goodbye </font>&quot; ); %> </BODY> </HTML> 1. as quoted html example10a. jsp 2. as direct html 3. in print statement http://localhost:8080/myapp/chapter03/example10a.jsp Different ways JSP can output HTML:
http://localhost:8080/myapp/chapter03/example12a.html chapter03/example12a.html http://localhost:8080/myapp/chapter03/getFontEffect.jsp?Name=Mimi&font=4 Form  => name & font fields =>  JSP program  => returns dynamic html
<HTML> <HEAD> <TITLE>  font effect  </TITLE> </HEAD> <BODY> <H1> Please sign </H1> <form name = &quot;formName&quot; ACTION = &quot; getFontEffect.jsp &quot;  Method =&quot; GET &quot; > Font size:  <input type=text name=  font   size=24>  <br> Type name:  <input type=text name=  Name   size=24>  <br> <input type=submit value=&quot;submit&quot;  > <input type=reset  value=&quot;Clear Form&quot;  > </form> </BODY> </HTML> chapter03/example12a.html Form
<HTML> <HEAD> <TITLE>  get User information  </TITLE> </HEAD> <BODY> <H1> Hi there - how are you?  </H1> <% out.print ( &quot;<font size = &quot; ); out.print (request.getParameter(&quot;font&quot;)); out.print (&quot;  color = blue> &quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print ( &quot;</font>&quot;) ; %> </BODY> </HTML> chapter03/ getFontEffect.jsp JSP page triggered by form: This builds font statement: <font  size =  font.value   color = blue>  Name.value   </font>
<HTML> <HEAD> <TITLE>  get User information  </TITLE> </HEAD> <BODY> <H1> Hi there - how are you?  </H1> <% out.print(&quot; <font size =  &quot;); out.print( request.getParameter(&quot; font &quot;)  ); out.print(&quot;  color =  &quot;); out.print( request.getParameter(&quot; colorName &quot;) ); out.print(&quot; > &quot;); out.print( request.getParameter(&quot; Name &quot;) ); out.print(&quot; </font> &quot;); %> </BODY> </HTML> make the  font tag prefix font text font tag suffix used as color [blue, red...] used as text [double use] chapter03/ getFontEffect2.jsp Variation [uses Name as color choice]  http://localhost:8080/myapp/chapter03/ example12a1.html
JSP control structure and Html  Experiment:  Retrieve font values from an HTML form &    return name in font depending on hour of day 1.  chapter03/example12b.html  =>  returns form 2.  chapter03/ifThenElseHtml.jsp  =>  returns time-sized name
<HTML> <HEAD> <TITLE>  font effect  </TITLE> </HEAD> <BODY> <H1> Please sign </H1> <form name = &quot;formName&quot; ACTION = &quot; ifThenElseHtml.jsp &quot;  Method =&quot; GET &quot; > Your Name:  <input type=text name=  Name   size=24>  <br> Select font:  <input type=text name=  font   size=24>  <br> <input type=submit value=&quot;submit&quot;  > <input type=reset  value=&quot;Clear Form&quot;  > </form> </BODY> </HTML> chapter03/example12b.html requested JSP program
 
chapter03/ ifThenElseHtml.jsp <HTML> <HEAD> <TITLE>  time-based display </TITLE> </HEAD> <BODY> <H1> Hi there - how are you?  </H1> <% java.util.Calendar date = java.util.Calendar.getInstance(); int hour = date.get(date.HOUR_OF_DAY); if  (hour <= 15) { out.print (&quot;<font size = &quot;); out.print (request.getParameter(&quot;font&quot;)); out.print (&quot;  color = blue>&quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print (&quot;</font>&quot;); } else   { out.print (&quot;<font size = 10&quot;); out.print (&quot;  color = red>&quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print (&quot;</font>&quot;); } %> <BR><BR> <a href = &quot;example12b.html&quot; > Link Illustration </a> </BODY>
<HTML> <HEAD> <TITLE>  time-based display </TITLE> </HEAD> <BODY> <H1> Hi there - how are you?  </H1> <% java.util.Calendar date = java.util.Calendar.getInstance(); int hour = date.get(date.HOUR_OF_DAY); if (hour <= 15) { out.print (&quot;<font size = &quot;); out.print (request.getParameter(&quot;font&quot;)); out.print (&quot;  color = blue>&quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print (&quot;</font>&quot;); } else  { out.print (&quot;<font size = 10&quot;); out.print (&quot;  color = red>&quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print (&quot;</font>&quot;); } %> <BR><BR> <a href = &quot;example12b.html&quot; > Link Illustration </a> </BODY>

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Servlet and jsp interview questions
Servlet and jsp interview questionsServlet and jsp interview questions
Servlet and jsp interview questions
 
JAVA SERVER PAGES
JAVA SERVER PAGESJAVA SERVER PAGES
JAVA SERVER PAGES
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp
JspJsp
Jsp
 
JSP - Java Server Page
JSP - Java Server PageJSP - Java Server Page
JSP - Java Server Page
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Implicit objects advance Java
Implicit objects advance JavaImplicit objects advance Java
Implicit objects advance Java
 
JSP Processing
JSP ProcessingJSP Processing
JSP Processing
 
JSP Scope variable And Data Sharing
JSP Scope variable And Data SharingJSP Scope variable And Data Sharing
JSP Scope variable And Data Sharing
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
 
Jsp sasidhar
Jsp sasidharJsp sasidhar
Jsp sasidhar
 
Jsp
JspJsp
Jsp
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Unit 4 web technology uptu
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptu
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE  AND JSP PROCESSINGINTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE  AND JSP PROCESSING
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Jsp lecture
Jsp lectureJsp lecture
Jsp lecture
 

Ähnlich wie Apache Tomcat Server-Side Scripts

JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESYoga Raja
 
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)JavaEE Trainers
 
SCWCD 2. servlet req - resp (cap3 - cap4)
SCWCD 2. servlet   req - resp (cap3 - cap4)SCWCD 2. servlet   req - resp (cap3 - cap4)
SCWCD 2. servlet req - resp (cap3 - cap4)Francesco Ierna
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentationengcs2008
 
JSP diana y yo
JSP diana y yoJSP diana y yo
JSP diana y yomichael
 
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7phuphax
 
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7phuphax
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API07.pallav
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsJavaEE Trainers
 

Ähnlich wie Apache Tomcat Server-Side Scripts (20)

Jsp 01
Jsp 01Jsp 01
Jsp 01
 
C:\fakepath\jsp01
C:\fakepath\jsp01C:\fakepath\jsp01
C:\fakepath\jsp01
 
Jsp
JspJsp
Jsp
 
JSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGESJSP- JAVA SERVER PAGES
JSP- JAVA SERVER PAGES
 
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
Servlet/JSP course chapter 2: Introduction to JavaServer Pages (JSP)
 
29 Jsp
29 Jsp29 Jsp
29 Jsp
 
SCWCD 2. servlet req - resp (cap3 - cap4)
SCWCD 2. servlet   req - resp (cap3 - cap4)SCWCD 2. servlet   req - resp (cap3 - cap4)
SCWCD 2. servlet req - resp (cap3 - cap4)
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Ajax
AjaxAjax
Ajax
 
Jsp slides
Jsp slidesJsp slides
Jsp slides
 
Jsp
JspJsp
Jsp
 
Jsp
JspJsp
Jsp
 
JSP diana y yo
JSP diana y yoJSP diana y yo
JSP diana y yo
 
ASP.NET MVC
ASP.NET MVCASP.NET MVC
ASP.NET MVC
 
Unit 4 1 web technology uptu
Unit 4 1 web technology uptuUnit 4 1 web technology uptu
Unit 4 1 web technology uptu
 
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7
 
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 5/7
 
Ajax
AjaxAjax
Ajax
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servlets
 

Kürzlich hochgeladen

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 

Kürzlich hochgeladen (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 

Apache Tomcat Server-Side Scripts

  • 1. Servers - Apache Tomcat Server Server-side scripts - Java Server Pages Java Server Pages - Xue Bai
  • 2. Objectives What is Request/Response protocol for a client-side script What is Request/Response protocol for server-side script How does server interact with multiple concurrent clients How can html meta-tag s control request/response interaction How does effect depend on file extension - html versus jsp
  • 3. I: client-side, server-side, .jsp, JavaScript form screening, JSP results, multi-threaded server responses, Html meta-tag refresh, need for .jsp versus .html extension, JSP’s conditional generation of Html, forms, buttons, onClick event, JavaScript function, reset, role of names on forms to identify form elements, table definition, textfields, alert pop-up window, configuring for Apache Tomcat server, Class & ClassPath system environment variables, <script & <% tags for JavaScript & JSP II: form - events - extend form, yjspapphapter02example14.html, qualified names for elements, submitting form data, request/response cycle[38], GET method:processing by server-side program, submit button, method identification, how element names are used, how JSP program accesses form element values, run: chapter03xample6a.html example - note query string sent to server - in address field of browser - after submit clicked - un-highlight beforehand so visible, focus attention, request.getParameter method, JSP Html dynamic output, dynamic html example: 12a http://localhost:8080/myapp/chapter03/example6a.html http://localhost:8080/myapp/chapter03/example10a.jsp - contrast Netscape & IE http://localhost:8080/myapp/chapter03/example12a.html & 12b Topics
  • 4. client 1. requests URL for html page server 2. retrieves html page 3. sends html page to client 4. browser interprets html page & displays Typical html Request/Response cycle
  • 5. Request/Response for page - JavaScript commands client 1. requests URL for html page server 2. retrieves html page 3. responds w. page to client 4. interprets page - (browser) executes Java script commands eg: check for bad or missing data on form with embedded JavaScript commands CLIENT-SIDE SCRIPT (Apache Tomcat)
  • 6. 4. interprets page - Request/Response for page - with JavaScript commands executes Java script Commands client server 3. sends page to client 1. requests page 2. gets page
  • 7. 1 - requests JSP page server 2 - retrieves page 3 - responds with html+results in page browser executes server-side script may have embedded JSP server script & Java-client-Script Request/Response for file with Java Server Page parts SERVER-SIDE SCRIPT
  • 8. Request/Response for Java Server Page client 1. sends URL for JSP page server 2. retrieves page from storage 3. sends html + results to client 4. browser displays page executes JSP code replaces code with exec results * compiled first time only - thereafter uses compiled copy experiment on effect of extensions like .jsp or .html compiles embedded JSP code *
  • 9. 2 - retrieves page using URL addr & server configuration 1 - requests JSP page server 3 - responds & html + results browser executes client-side script executes server-side script http://localhost:8080 /myapp /chapter02/example2a.html Context path= &quot; /myapp &quot; docBase= &quot;c:yjspapp&quot; http://localhost:8080/ c:yjspapp hapter02xample2a.html
  • 10. Experiment: JSP versus JavaScript - client v. server execution 1. Start Apache Tomcat server listening on port 8080 localhost 2. Request a Java Server page from server - source file will have Results 3. Request html page with JavaScript - source page will have the JavaScript [at least in Explorer - not Netscape] 2. C:yjspapphapter01xample2. jsp 3. C:yjspapphapter02xample2a. html – prev slide Start Tomcat server from start Menu or shortcut on desktop
  • 11. <html> <head> <title> current server time </title> </head> <font face = &quot;Arial&quot; size =4> The current Date and time on the web server are: <BR> <%= new java.util.Date() %> </font> </body> </html> Request for JSP .jsp page retrieved is: embedded jsp instruction jsp instruction - executed on &quot;server-side&quot; - result replaces code C:yjspapphapter01xample2. jsp
  • 12. 1. Request this page from server which is Listening on port 8080 2. Contents sent by server - after executing jsp code located in requested file
  • 13. <html> <head> <title> current server time </title> </head> <font face = &quot;Arial&quot; size =4> The current Date and time on the web server are: <BR> Wed Nov 27 20:27:02 EST 2002 </font> </body> </html> 1. &quot; source &quot; as shown in browser 2. Note how Date’s Result replaces original JSP in page sent to browser
  • 14. sent to browser and executed on browser requested source page is same as displayed in browser Request for Java Script page <HTML> <HEAD> <TITLE>Client-side script </TITLE></HEAD> <BODY> THE TIME ON THE CLIENT IS: Current time is: <%= new java.util.Date( ) %> <script language=&quot;JavaScript&quot; > document.write (new Date() ) </script> </BODY> </HTML> C:yjspapphapter02xample2a .html Request from server - versus drag-and-drop in browser - observe address bar Why not executed on server ?
  • 15. JavaScript Request response displayed in browser Source shows only JavaScript code - not the computed date
  • 16. How can a server interface with multiple client browsers simultaneously ? Ans: creates multiple threads - one per browser. Experiment: JSP with refresh meta-tag from multiple browsers Use URL: http://localhost:8080/myapp/chapter02/ example12.jsp Source contains Html Meta tag : < META HTTP-EQUIV = &quot;REFRESH&quot; CONTENT = &quot;5, URL=example12.jsp&quot;> and JSP instruction : <%= new java.util.Date() %>
  • 17. <HTML> <HEAD> <TITLE> server-side scripts </TITLE> < META HTTP-EQUIV = &quot;REFRESH&quot; CONTENT = &quot;5, URL=example12.jsp&quot;> </HEAD> <BODY> The time on the server is: <%= new java.util.Date( ) %> </BODY> </HTML> JSP page requested is: requested every 5 sec from current directory of original request JSP result replaces this code & is sent to browser URL: http://localhost:8080/myapp/chapter02/ example12.jsp
  • 18. IP address of server port that server listens on Requested File’s address on the server remainder of file address path server uses configuration file to convert this to initial part of path: &quot;http://localhost: helloWorld.js 8080 /myapp/ WHERE WHICH WHAT C:yjspapp
  • 19. What happens if you request an html page that has embedded JSP ?
  • 20. -- effect of EXTension on how server handles request: Effect of suffix: http://localhost:8080/myapp/chapter01/project3. html versus http://localhost:8080/myapp/chapter01/project3. jsp Source html contains Java Server Page instructions - java inside jsp tags: <% ... %> <% java.util.Calendar calendar = java.util.Calendar.getInstance( ); int hour = calendar .get(calendar.HOUR_OF_DAY); if ( hour <12) { %> <h3>Good morning!</h3> <% } else { %> <h3>Good afternoon!</h3> <% } %> JSP ...it would be better to just use print statement – this looks confusing.
  • 21. <HTML> <HEAD><TITLE>Welcome to JSP</TITLE></HEAD> <BODY> <% java.util.Calendar calendar = java.util.Calendar.getInstance(); int hour = calendar.get(calendar.HOUR_OF_DAY); if ( hour < 12) { %> Hour is <br> <%= hour %> <h3>Good morning!</h3> <%}else {%> <h3>Good afternoon!</h3> <%}%> </BODY> </HTML> project3. jsp versus same file with different extension: project3. html HTML – green JSP – red / blue JSP starts/stops with <% … %> Html can occur anywhere else
  • 22. Page displayed for project3. jsp : Good afternoon! Welcome to Introduction to JSP In this chapter, you: learned about Web client/server architecture learned the difference between static and dynamic Web pages learned how dynamic Web pages are generated in JSP reviewed various server-side processing technologies compared JSP to alternate time-dependent jsp output
  • 23. Displayed page For project3 . html IE browser - no result (and no JSP shown) Good morning! Good afternoon! Welcome to Introduction to JSP In this chapter, you: learned about Web client/server architecture learned the difference between static and dynamic Web pages learned how dynamic Web pages are generated in JSP reviewed various server-side processing technologies compared JSP to alternate technologies
  • 24. Netscape - no result (JSP shown) <% java.util.Calendar calendar = java.util.Calendar.getInstance(); int hour = calendar.get(calendar.HOUR_OF_DAY); if( hour<12){%> Good morning! <%} else {%> Good afternoon! <%}%> Welcome to Introduction to JSP In this chapter, you: learned about Web client/server architecture learned the difference between static and dynamic Web pages learned how dynamic Web pages are generated in JSP reviewed various server-side processing technologies compared JSP to alternate technologies Displayed page project3 . html
  • 26. How does request/response protocol operate for forms & jsp pages How do you submit form data to server using GET method? Objectives - Understand How to configure a (Tomcat) server How do you dynamically construct Html using Java Server Pages What is the URL format How do JSP programs get data from forms
  • 27. How do you submit form data to server using GET method? C:yjspapphapter03xample6a.html C:yjspapphapter03etUserInfo.jsp
  • 28.
  • 29. Request/Response protocol 2. retrieve html form browser 4. display form - user enters data & submits form 6. triggers retrieving, compiling getUserInfo.jsp referred to on form - executes jsp with data from query-string 1. request html page example6a.html 3. returns form 7. returns results to client 5. sends URL +query-string chapter03xample6a.html server understand thoroughly
  • 30. <HTML> <HEAD> <TITLE> Submit using GET Method </TITLE> </HEAD> <BODY> <H1> Please sign </H1> <form name = &quot;formName&quot; ACTION = &quot; getUserInfo.jsp &quot; Method =&quot; GET &quot; > Your Name: <input type=text name= firstName size=24 > <br> Your Major: <input type=text name= major size=24 > <br> <input type= submit value=&quot;submit&quot; > <input type=reset value=&quot;Clear Form&quot; > </form> THE TIME ON THE CLIENT IS: <script language=&quot;JavaScript&quot; > document.write (new Date( ) ) </script> </BODY> </HTML> example6a.html jsp program executed on Submit triggers submission of query string to server GET sends data in query-string data names
  • 31. Query string sent by browser to server: http://localhost:8080/ myapp/chapter03/getUserInfo.jsp ? firstName=aaa&major=zzz jsp to execute data for program SERVER PROGRAM DATA FOR PROGRAM WHERE WHO WHAT
  • 32. <HTML> <HEAD> <TITLE> get User information </TITLE> </HEAD> <BODY> <H1> Hi there - how are you? </H1> Your major is: <%= request.getParameter(&quot;major&quot;) %> <br> Your name is: <%= request.getParameter(&quot;firstName&quot;) %> <br> <br> The current Date and time on the web server are: <BR> <%= new java.util.Date() %> <br> </BODY> </HTML> getUserInfo.jsp retrieves values entered on form which are returned in query string field names on html form that triggered execution of getUserInfo.jsp
  • 33. <HTML> <HEAD> <TITLE> get User information </TITLE> </HEAD> <BODY> <H1> Hi there - how are you? </H1> Your major is: <%= request.getParameter(&quot; major &quot;) %> <br> Your name is: <%= request.getParameter(&quot; firstName &quot;) %> <br> <br> The current Date and time on the web server are: <BR> <%= new java.util.Date() %> <br> </BODY> </HTML> getUserInfo.jsp http://localhost:8080/ myapp/chapter03/getUserInfo.jsp ? firstName =aaa& major =zzz DATA FOR PROGRAM
  • 34. C:yjspapp hapter01ilename http://localhost:8080/ myapp /chapter01/filename so file retrieved is: replaced with C:/myjspapp because of server configuration Requested file on server Server IP Interpretation of URL port The context prefix myapp makes the web site Relocateable. You just change myapp to point to the directory where site pages begin.
  • 35. How do you configure the Tomcat server ?
  • 36. Environment setup 1. control panel > system > advanced > environment variables > system variables %SystemRoot%ystem32;%SystemRoot%; %SystemRoot%ystem32bem; C:dk1.2.2in ...on one line points to JDK bin update PATH variable to include JDK 2. similarly add CLASSPATH system variable defined as : C:dk1.2.2reibt.jar; .; C:rogram Filespache Tomcat 4.0ommonibervlet.jar; C:yjspappEB-INFLASSES … all on a single line Assumes jdk 1.2.2 -- same idea for other versions of jdk.
  • 37. Environment setup 1. start > all programs > Apache Tomcat 4.0 > Edit Configuration file right after: <!-- Tomcat Root Context --> <!-- <Context path=&quot;&quot; docBase=&quot;ROOT&quot; debug=&quot;0&quot;/> --> add: <Context path= &quot;/myapp&quot; docBase= &quot;c:yjspapp&quot; debug=&quot;0&quot; reloadable=&quot;true&quot; /> http://localhost:8080/ myapp /chapter01/filename 1. this 2. gets expanded to this
  • 38. Environment setup 1. start > all programs > Apache Tomcat 4.0 > Edit Configuration file add: <Context path= &quot;/myapp&quot; docBase= &quot;c:yjspapp&quot; debug=&quot;0&quot; reloadable=&quot;true&quot; /> http://localhost:8080 /myapp/chapter03/example6.html If user wants: C:yjspapphapter03xample6.html then asks for:
  • 39. What are the advantages of using a client-side versus server-side script ? Client-side script can prevent bad data being sent to server which would waste user’s time, server’s time, and waste communication resources Server-side script allows protected server-side access to data on the server side.
  • 40. <HTML> <HEAD> <TITLE> jsp output </TITLE> </HEAD> <BODY> <%= &quot;<font size =6 color = red> Hello </font>&quot; %> <br><br> <font size =4 color = blue> How are you? </font> <br><br> <% out.println ( &quot;<font size = 8 color = green> Goodbye </font>&quot; ); %> </BODY> </HTML> 1. as quoted html example10a. jsp 2. as direct html 3. in print statement http://localhost:8080/myapp/chapter03/example10a.jsp Different ways JSP can output HTML:
  • 42. <HTML> <HEAD> <TITLE> font effect </TITLE> </HEAD> <BODY> <H1> Please sign </H1> <form name = &quot;formName&quot; ACTION = &quot; getFontEffect.jsp &quot; Method =&quot; GET &quot; > Font size: <input type=text name= font size=24> <br> Type name: <input type=text name= Name size=24> <br> <input type=submit value=&quot;submit&quot; > <input type=reset value=&quot;Clear Form&quot; > </form> </BODY> </HTML> chapter03/example12a.html Form
  • 43. <HTML> <HEAD> <TITLE> get User information </TITLE> </HEAD> <BODY> <H1> Hi there - how are you? </H1> <% out.print ( &quot;<font size = &quot; ); out.print (request.getParameter(&quot;font&quot;)); out.print (&quot; color = blue> &quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print ( &quot;</font>&quot;) ; %> </BODY> </HTML> chapter03/ getFontEffect.jsp JSP page triggered by form: This builds font statement: <font size = font.value color = blue> Name.value </font>
  • 44. <HTML> <HEAD> <TITLE> get User information </TITLE> </HEAD> <BODY> <H1> Hi there - how are you? </H1> <% out.print(&quot; <font size = &quot;); out.print( request.getParameter(&quot; font &quot;) ); out.print(&quot; color = &quot;); out.print( request.getParameter(&quot; colorName &quot;) ); out.print(&quot; > &quot;); out.print( request.getParameter(&quot; Name &quot;) ); out.print(&quot; </font> &quot;); %> </BODY> </HTML> make the font tag prefix font text font tag suffix used as color [blue, red...] used as text [double use] chapter03/ getFontEffect2.jsp Variation [uses Name as color choice] http://localhost:8080/myapp/chapter03/ example12a1.html
  • 45. JSP control structure and Html Experiment: Retrieve font values from an HTML form & return name in font depending on hour of day 1. chapter03/example12b.html => returns form 2. chapter03/ifThenElseHtml.jsp => returns time-sized name
  • 46. <HTML> <HEAD> <TITLE> font effect </TITLE> </HEAD> <BODY> <H1> Please sign </H1> <form name = &quot;formName&quot; ACTION = &quot; ifThenElseHtml.jsp &quot; Method =&quot; GET &quot; > Your Name: <input type=text name= Name size=24> <br> Select font: <input type=text name= font size=24> <br> <input type=submit value=&quot;submit&quot; > <input type=reset value=&quot;Clear Form&quot; > </form> </BODY> </HTML> chapter03/example12b.html requested JSP program
  • 47.  
  • 48. chapter03/ ifThenElseHtml.jsp <HTML> <HEAD> <TITLE> time-based display </TITLE> </HEAD> <BODY> <H1> Hi there - how are you? </H1> <% java.util.Calendar date = java.util.Calendar.getInstance(); int hour = date.get(date.HOUR_OF_DAY); if (hour <= 15) { out.print (&quot;<font size = &quot;); out.print (request.getParameter(&quot;font&quot;)); out.print (&quot; color = blue>&quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print (&quot;</font>&quot;); } else { out.print (&quot;<font size = 10&quot;); out.print (&quot; color = red>&quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print (&quot;</font>&quot;); } %> <BR><BR> <a href = &quot;example12b.html&quot; > Link Illustration </a> </BODY>
  • 49. <HTML> <HEAD> <TITLE> time-based display </TITLE> </HEAD> <BODY> <H1> Hi there - how are you? </H1> <% java.util.Calendar date = java.util.Calendar.getInstance(); int hour = date.get(date.HOUR_OF_DAY); if (hour <= 15) { out.print (&quot;<font size = &quot;); out.print (request.getParameter(&quot;font&quot;)); out.print (&quot; color = blue>&quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print (&quot;</font>&quot;); } else { out.print (&quot;<font size = 10&quot;); out.print (&quot; color = red>&quot;); out.print (request.getParameter(&quot;Name&quot;)); out.print (&quot;</font>&quot;); } %> <BR><BR> <a href = &quot;example12b.html&quot; > Link Illustration </a> </BODY>