SlideShare a Scribd company logo
JSP Basic By:  Mr. PHUPHA PUNYAPOTASAKUL ( ภูผา ปัญญาโพธาสกุล )
Lab outstanding Style sheet Java Script Eclipse JSP Basic
Road map from now Week 6 – (8/12/2007) Lecture Week 7 – Lab home work Week 8 – Mid-term Week 9 – Lecture + Lab quiz
Mid-term exam คะแนนรวม  50  คะแนน หัวข้อที่สอบ HTTP, HTML 17  คะแนน Style sheet 13  คะแนน Java Script 13  คะแนน JSP Basic 7  คะแนน ลักษณะคำถาม Multiple choice  รวม  24  คะแนน เติมคำ   +  แสดงวิธีทำ  26  คะแนน
JSP Basic JSP Script let <% .. %> JSP Expression <%= .. %> same as out.print(“..”); JSP Declaration <%! .. %> JSP Comment <%-- .. --%>
How does it work? JSP file (*.jsp) Servlet (*.java) Class file (*.class) Compile
Example JSP < %  if  ( Math . random ()  < 0.5 )  {  % > Have a <B>nice< / B> day !  < %  } else {  % > Have a <B>lousy< / B> day ! < %  }  % > Convert to if  ( Math . random ()  < 0.5 )  { out . println (&quot; Have a <B>nice< / B> day !&quot;) ; } else { out . println (&quot; Have a <B>lousy< / B> day !&quot;) ; }
View Converted Files Tomcat /{tomcat_dir}/work/.. Eclipse + Tomcat /{eclipse_workspace}/ . metadata / . plugins/org . eclipse . wst . server . core/tmp0/work
Servlet Object javax . servlet . Servlet javax . servlet . jsp . JspPage javax.servlet.jsp.HttpJspPage Server implementation Class e.g.  org.apache.jasper.runtime.HttpJspBase Each page e.g.  org . apache . jsp . userman. { jspfilename }_jsp
JSP Page Directive Syntax <%@ page att=“val” %> Attributes import =&quot; package.class &quot;  contentType=&quot; MIME - Type &quot;  isThreadSafe =&quot; true |false &quot;  session=&quot; true |false&quot;  buffer =&quot; size kb|none &quot;  autoflush=&quot; true |false&quot;  extends =&quot; package.class &quot;  info=&quot; message &quot;  errorPage =&quot; url &quot;  isErrorPage=&quot;true| false &quot;  language =&quot; java &quot;
JSP Include Directive Syntax < % @ include file =&quot; url &quot; % > Compile time including URL must be in local
JSP Action jsp : include  - Include a file at the time the page is requested.  jsp:useBean  -  Find or instantiate a JavaBean   jsp : setProperty  - Set the property of a JavaBean. jsp:getProperty  -  Insert the property of a JavaBean into the output .  jsp : forward  - Forward the requester to a new page.
JSP Include Include at run time in the way that execute pages separately and then combine output later Attributes page =&quot; {  relativeURL  | < %=  expression  % > } &quot;  The relative URL that locates the resource to be included, or an expression that evaluates to a  String  equivalent to the relative URL. flush=&quot;true  |  false &quot;  If the page output is buffered and the flush attribute is given a true value, the buffer is flushed prior to the inclusion, otherwise the buffer is not flushed. The default value for the flush attribute is  false .
JSP Param Using with JSP Include, Forward <jsp : include page =&quot; scripts / login . jsp &quot; >   <jsp : param name =&quot; username &quot;  value =&quot; jsmith &quot; / >   <jsp : param name =“ password &quot;  value =“ xxxx &quot; / >  < / jsp : include>   Use to submit request parameters to included page
JSP Forward Redirect to anther URL using HTTP header Beware when using JSP Forward with page:cache=“none”, cause IllegalStateException Attributes page=&quot;{ relativeURL  | <%=  expression  %>}&quot;  A  String  or an expression representing the relative URL of the component to which you are forwarding the request .  The component can be another JSP page, a servlet, or any other object that can respond to a request .  May use together with JSP Param
JSP useBean locates or instantiates a JavaBeans component.  F irst ly  attempts to locate an instance of the bean. If the bean does not exist,  just  instantiates it   Example <jsp : useBean id =“ userobj &quot;  class =“ test.UserObj &quot;  scope=“session” / >
Java Bean   Example public class MyBean{ private String username=“”; private String password=“”; public String getUsername(){ return username; } public String getPassword(){ return password; } public void setUsername(String u){ username=u; } public void setPassword(String p){ password=p; } }
JSP useBean   Attributes id =&quot; beanInstanceName &quot;  A variable that identifies the bean in the scope you specify. You can use the variable name in expressions or scriptlets in the JSP page.  scope=&quot; page |request|session|application“ class =&quot; package.class &quot;  t ype=&quot; package . class “ What is different between class and type? TypeName bean=new ClassName();
JSP setProperty The  <jsp : setProperty>  element sets the value of one or more properties in a bean, using the bean's setter methods. You must declare the bean with  < jsp : useBean >   before  you set a property value with  <jsp : setProperty> . ( Copy value from request parameters ) Because  <jsp : useBean>  and  <jsp : setProperty>  work together, the bean instance names they use must match (that is, the value of  name  in  <jsp : setProperty>  and the value of  id  in  <jsp : useBean>  must be the same).
JSP setProperty Example <jsp : setProperty name =&quot; mybean &quot;  property =&quot;*&quot; / > <jsp : setProperty name =&quot; mybean &quot;  property =&quot; username &quot; / > <jsp : setProperty name =&quot; mybean &quot;  property =&quot; username &quot;  value =&quot; Steve &quot; / >   Equals to mybean.setUsername(request.getParameter(“username”))
Predefined (Built-in) Variables request This is the  HttpServletRequest  associated with the request, and lets you look at the request parameters (via  getParameter ), the request type ( GET ,  POST ,  HEAD , etc.), and the incoming HTTP headers (cookies,  Referer , etc.).   response This is the  HttpServletResponse  associated with the response to the client. Note that, since the output stream (see  out  below) is buffered, it  is  legal to set HTTP status codes and response headers, even though this is not permitted in regular servlets once any output has been sent to the client.
Predefined (Built-in) Variables out This is the  PrintWriter  used to send output to the client .  However, in order to make the  response  object  ( see the previous section )  useful, this is a buffered version of  PrintWriter  called  JspWriter.  Note that you can adjust the buffer size, or even turn buffering off, through use of the  buffer  attribute of the  page  directive .  session This is the  HttpSession  object associated with the request . application This is the  ServletContext  as obtained via  getServletConfig().getContext().
Predefined (Built-in) Variables config This is the  ServletConfig  object for this page. User’s defined configuration in web.xml can be retrieve using this object page This is simply a synonym for  this , and is not very useful in Java. It was created as a placeholder for the time when the scripting language could be something other than Java.
Question & Answer

More Related Content

PPT
Jsp Presentation +Mufix "3"
PPT
Rich faces
PPTX
Implicit objects advance Java
PPT
Jsp Slides
PPTX
Jsp elements
PPTX
Implicit object.pptx
PPTX
Servlet and jsp interview questions
PPT
Jsp slides
Jsp Presentation +Mufix "3"
Rich faces
Implicit objects advance Java
Jsp Slides
Jsp elements
Implicit object.pptx
Servlet and jsp interview questions
Jsp slides

What's hot (20)

PPTX
Jsp presentation
PPT
PDF
Lap trinh web [Slide jsp]
PPT
Processing XML with Java
PPTX
PPTX
ADP- Chapter 3 Implementing Inter-Servlet Communication
PPTX
ADP - Chapter 5 Exploring JavaServer Pages Technology
ODP
Os Leonard
PPT
Java Server Pages
PPTX
JAVA SERVER PAGES
PDF
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
PPTX
jQuery from the very beginning
PPTX
Jsp config implicit object
PPS
Jsp element
TXT
Jsp Notes
PDF
Jsp quick reference card
DOCX
PPS
Jsp chapter 1
PDF
J2EE jsp_01
Jsp presentation
Lap trinh web [Slide jsp]
Processing XML with Java
ADP- Chapter 3 Implementing Inter-Servlet Communication
ADP - Chapter 5 Exploring JavaServer Pages Technology
Os Leonard
Java Server Pages
JAVA SERVER PAGES
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 7 ...
jQuery from the very beginning
Jsp config implicit object
Jsp element
Jsp Notes
Jsp quick reference card
Jsp chapter 1
J2EE jsp_01
Ad

Viewers also liked (20)

PPTX
Preparing for Failure - Best Practise for Incident Response
PPTX
Kansainvälisyysstrategia 2.0 ja OPS-2016
PPT
Finnish baseball
PPT
Cineas Corso Taylor Made Per Zurich 27 Aprile 2010 Mattina
PPTX
Twelve Gods of Olympus
PPT
Lunch Recipe from Romania
PDF
Let's go home
PPT
PDF
Case Note Record
PPTX
Learning from History
PDF
How to add a canvas to your image
PPT
KMUTNB - Internet Programming 3/7
PDF
Interesting Sights in Orivesi
PDF
Exporting Your In Design Portfolio
PDF
Long Life Bicycles
PPT
MVT Asia Presentation
PPT
eTwinning - lyhyt johdatus työpajatyöskentelyyn
PPTX
Hazcrowd for Crowdsourcing
PPT
Monitoring Student Work In Moodle Delise Fathers April 2009
PDF
Can Taltavuit Ibiza. Magnificient Villa for Vacation Rentals in Ibiza
Preparing for Failure - Best Practise for Incident Response
Kansainvälisyysstrategia 2.0 ja OPS-2016
Finnish baseball
Cineas Corso Taylor Made Per Zurich 27 Aprile 2010 Mattina
Twelve Gods of Olympus
Lunch Recipe from Romania
Let's go home
Case Note Record
Learning from History
How to add a canvas to your image
KMUTNB - Internet Programming 3/7
Interesting Sights in Orivesi
Exporting Your In Design Portfolio
Long Life Bicycles
MVT Asia Presentation
eTwinning - lyhyt johdatus työpajatyöskentelyyn
Hazcrowd for Crowdsourcing
Monitoring Student Work In Moodle Delise Fathers April 2009
Can Taltavuit Ibiza. Magnificient Villa for Vacation Rentals in Ibiza
Ad

Similar to KMUTNB - Internet Programming 5/7 (20)

PPTX
Learning jsp
PPT
PPTX
JSP.pptx programming guide for beginners and experts
PPTX
JSP AND XML USING JAVA WITH GET AND POST METHODS
PPTX
สปริงเฟรมเวิร์ค4.1
PPT
Web&java. jsp
PPT
Web&java. jsp
PPTX
C:\fakepath\jsp01
PPTX
JSP- JAVA SERVER PAGES
PPT
PPTX
Introduction - Java Server Programming (JSP)
PPT
29 Jsp
PPTX
Introduction to JSP.pptx
PPT
Jsp 02(jsp directives)2003
PPT
Boston Computing Review - Java Server Pages
PPT
I Feel Pretty
PPT
Unified Expression Language
PPTX
JSP Directives IMPLICIT ACTIONS and HACKING.pptx
Learning jsp
JSP.pptx programming guide for beginners and experts
JSP AND XML USING JAVA WITH GET AND POST METHODS
สปริงเฟรมเวิร์ค4.1
Web&java. jsp
Web&java. jsp
C:\fakepath\jsp01
JSP- JAVA SERVER PAGES
Introduction - Java Server Programming (JSP)
29 Jsp
Introduction to JSP.pptx
Jsp 02(jsp directives)2003
Boston Computing Review - Java Server Pages
I Feel Pretty
Unified Expression Language
JSP Directives IMPLICIT ACTIONS and HACKING.pptx

More from phuphax (8)

PDF
GPS Tracking by Tracking.in.th
PPT
KMUTNB - Internet Programming 7/7
PPT
KMUTNB - Internet Programming 6/7
PPT
KMUTNB - Internet Programming 5/7
PPT
KMUTNB - Internet Programming 4/7
PPT
KMUTNB - Internet Programming 2/7
PPT
KMUTNB - Internet Programming 1/7
PPS
Abzolute Logistic Solution
GPS Tracking by Tracking.in.th
KMUTNB - Internet Programming 7/7
KMUTNB - Internet Programming 6/7
KMUTNB - Internet Programming 5/7
KMUTNB - Internet Programming 4/7
KMUTNB - Internet Programming 2/7
KMUTNB - Internet Programming 1/7
Abzolute Logistic Solution

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Classroom Observation Tools for Teachers
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
01-Introduction-to-Information-Management.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
VCE English Exam - Section C Student Revision Booklet
human mycosis Human fungal infections are called human mycosis..pptx
Week 4 Term 3 Study Techniques revisited.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Classroom Observation Tools for Teachers
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
01-Introduction-to-Information-Management.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Anesthesia in Laparoscopic Surgery in India
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Microbial disease of the cardiovascular and lymphatic systems

KMUTNB - Internet Programming 5/7

  • 1. JSP Basic By: Mr. PHUPHA PUNYAPOTASAKUL ( ภูผา ปัญญาโพธาสกุล )
  • 2. Lab outstanding Style sheet Java Script Eclipse JSP Basic
  • 3. Road map from now Week 6 – (8/12/2007) Lecture Week 7 – Lab home work Week 8 – Mid-term Week 9 – Lecture + Lab quiz
  • 4. Mid-term exam คะแนนรวม 50 คะแนน หัวข้อที่สอบ HTTP, HTML 17 คะแนน Style sheet 13 คะแนน Java Script 13 คะแนน JSP Basic 7 คะแนน ลักษณะคำถาม Multiple choice รวม 24 คะแนน เติมคำ + แสดงวิธีทำ 26 คะแนน
  • 5. JSP Basic JSP Script let <% .. %> JSP Expression <%= .. %> same as out.print(“..”); JSP Declaration <%! .. %> JSP Comment <%-- .. --%>
  • 6. How does it work? JSP file (*.jsp) Servlet (*.java) Class file (*.class) Compile
  • 7. Example JSP < % if ( Math . random () < 0.5 ) { % > Have a <B>nice< / B> day ! < % } else { % > Have a <B>lousy< / B> day ! < % } % > Convert to if ( Math . random () < 0.5 ) { out . println (&quot; Have a <B>nice< / B> day !&quot;) ; } else { out . println (&quot; Have a <B>lousy< / B> day !&quot;) ; }
  • 8. View Converted Files Tomcat /{tomcat_dir}/work/.. Eclipse + Tomcat /{eclipse_workspace}/ . metadata / . plugins/org . eclipse . wst . server . core/tmp0/work
  • 9. Servlet Object javax . servlet . Servlet javax . servlet . jsp . JspPage javax.servlet.jsp.HttpJspPage Server implementation Class e.g. org.apache.jasper.runtime.HttpJspBase Each page e.g. org . apache . jsp . userman. { jspfilename }_jsp
  • 10. JSP Page Directive Syntax <%@ page att=“val” %> Attributes import =&quot; package.class &quot; contentType=&quot; MIME - Type &quot; isThreadSafe =&quot; true |false &quot; session=&quot; true |false&quot; buffer =&quot; size kb|none &quot; autoflush=&quot; true |false&quot; extends =&quot; package.class &quot; info=&quot; message &quot; errorPage =&quot; url &quot; isErrorPage=&quot;true| false &quot; language =&quot; java &quot;
  • 11. JSP Include Directive Syntax < % @ include file =&quot; url &quot; % > Compile time including URL must be in local
  • 12. JSP Action jsp : include - Include a file at the time the page is requested. jsp:useBean - Find or instantiate a JavaBean jsp : setProperty - Set the property of a JavaBean. jsp:getProperty - Insert the property of a JavaBean into the output . jsp : forward - Forward the requester to a new page.
  • 13. JSP Include Include at run time in the way that execute pages separately and then combine output later Attributes page =&quot; { relativeURL | < %= expression % > } &quot; The relative URL that locates the resource to be included, or an expression that evaluates to a String equivalent to the relative URL. flush=&quot;true | false &quot; If the page output is buffered and the flush attribute is given a true value, the buffer is flushed prior to the inclusion, otherwise the buffer is not flushed. The default value for the flush attribute is false .
  • 14. JSP Param Using with JSP Include, Forward <jsp : include page =&quot; scripts / login . jsp &quot; > <jsp : param name =&quot; username &quot; value =&quot; jsmith &quot; / > <jsp : param name =“ password &quot; value =“ xxxx &quot; / > < / jsp : include> Use to submit request parameters to included page
  • 15. JSP Forward Redirect to anther URL using HTTP header Beware when using JSP Forward with page:cache=“none”, cause IllegalStateException Attributes page=&quot;{ relativeURL | <%= expression %>}&quot; A String or an expression representing the relative URL of the component to which you are forwarding the request . The component can be another JSP page, a servlet, or any other object that can respond to a request . May use together with JSP Param
  • 16. JSP useBean locates or instantiates a JavaBeans component. F irst ly attempts to locate an instance of the bean. If the bean does not exist, just instantiates it Example <jsp : useBean id =“ userobj &quot; class =“ test.UserObj &quot; scope=“session” / >
  • 17. Java Bean Example public class MyBean{ private String username=“”; private String password=“”; public String getUsername(){ return username; } public String getPassword(){ return password; } public void setUsername(String u){ username=u; } public void setPassword(String p){ password=p; } }
  • 18. JSP useBean Attributes id =&quot; beanInstanceName &quot; A variable that identifies the bean in the scope you specify. You can use the variable name in expressions or scriptlets in the JSP page. scope=&quot; page |request|session|application“ class =&quot; package.class &quot; t ype=&quot; package . class “ What is different between class and type? TypeName bean=new ClassName();
  • 19. JSP setProperty The <jsp : setProperty> element sets the value of one or more properties in a bean, using the bean's setter methods. You must declare the bean with < jsp : useBean > before you set a property value with <jsp : setProperty> . ( Copy value from request parameters ) Because <jsp : useBean> and <jsp : setProperty> work together, the bean instance names they use must match (that is, the value of name in <jsp : setProperty> and the value of id in <jsp : useBean> must be the same).
  • 20. JSP setProperty Example <jsp : setProperty name =&quot; mybean &quot; property =&quot;*&quot; / > <jsp : setProperty name =&quot; mybean &quot; property =&quot; username &quot; / > <jsp : setProperty name =&quot; mybean &quot; property =&quot; username &quot; value =&quot; Steve &quot; / > Equals to mybean.setUsername(request.getParameter(“username”))
  • 21. Predefined (Built-in) Variables request This is the HttpServletRequest associated with the request, and lets you look at the request parameters (via getParameter ), the request type ( GET , POST , HEAD , etc.), and the incoming HTTP headers (cookies, Referer , etc.). response This is the HttpServletResponse associated with the response to the client. Note that, since the output stream (see out below) is buffered, it is legal to set HTTP status codes and response headers, even though this is not permitted in regular servlets once any output has been sent to the client.
  • 22. Predefined (Built-in) Variables out This is the PrintWriter used to send output to the client . However, in order to make the response object ( see the previous section ) useful, this is a buffered version of PrintWriter called JspWriter. Note that you can adjust the buffer size, or even turn buffering off, through use of the buffer attribute of the page directive . session This is the HttpSession object associated with the request . application This is the ServletContext as obtained via getServletConfig().getContext().
  • 23. Predefined (Built-in) Variables config This is the ServletConfig object for this page. User’s defined configuration in web.xml can be retrieve using this object page This is simply a synonym for this , and is not very useful in Java. It was created as a placeholder for the time when the scripting language could be something other than Java.