尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
Java Servlets Svetlin Nakov Borislava Spasova
Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Contents (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Servlets Technology Overview
What is a Java Servlet? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is a Java Servlet? (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Servlet Services ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why Use Servlets? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why Use Servlets? (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Time Servlet – Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Deploying Servlets on Eclipse IDE ,[object Object]
Deploying Servlets on Eclipse IDE (2) ,[object Object]
Deploying Servlets on Eclipse IDE (3) ,[object Object]
Deploying Servlets on Eclipse IDE (4) ,[object Object]
Java Servlets Technical Architecture
Servlets Architecture ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Servlets Architecture (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Servlets Architecture (3) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Servlets API ,[object Object],[object Object],[object Object],[object Object],HttpServletRequest.getParameter( String ) ServletConfig.getInitParameter () HttpServletRequest.getHeader( String )
Servlets API (2) ,[object Object],[object Object],[object Object],[object Object],HttpServletResponse.setHeader (<name>, <value>) /  HttpServletResponse.setContentType( String ) HttpServletResponse.getWriter() HttpServletResponse . getOutputStream() HttpServletResponse.sendRedirect()
Servlets Life-Cycle ,[object Object],[object Object],[object Object],init() ...() service() doGet() doPost() doDelete() destroy() doPut() New Destroyed Running
The init() Method ,[object Object],[object Object],[object Object],[object Object],[object Object]
The service() Method ,[object Object],[object Object],[object Object],[object Object]
The destroy() Method ,[object Object],[object Object],[object Object],[object Object],[object Object]
Java Servlets Examples
Processing Parameters – Hello Servlet ,[object Object],[object Object],[object Object],<form method=&quot; GET or POST &quot; action=&quot; the servlet &quot;>  <input type=&quot;text&quot; name=&quot; user_name &quot;> </form> String  n ame =   r equest.getParameter(&quot;user_name&quot;);
Hello Servlet – Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],HelloForm.html import java.io.*;  import javax.servlet.*;  import javax.servlet.http.*;  public class HelloServlet extends HttpServlet { Hello Servlet . java
Hello Servlet – Example public void doGet(HttpServletRequest  r equest, HttpServletResponse  r esponse) throws ServletException, IOException { r esponse.setContentType(&quot;text/html&quot;);  ServletOutputStream out =  r esponse.getOutputStream();  String userName =   r equest.getParameter(&quot;user_name&quot;);   out.println(&quot;<html> <head> &quot;);  out.println(&quot;<title>Hello Servlet</title>&quot;);  out.println(&quot;</head><body>&quot;);  out.println(&quot;<h1>Hello, &quot; + userName + &quot;</h1>&quot;);  out.println(&quot;</body></html>&quot;); } Hello Servlet . java
Creating The Form in Eclipse IDE ,[object Object]
Creating New Servlet in Eclipse IDE ,[object Object]
Hello Servlet in Action
Hello Servlet – HTTP Request ,[object Object],[object Object],GET /FirstWebApp/HelloServlet?user_name=Nakov   HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg,image/pjpeg, application/vnd.ms-excel,   application/vnd.ms-powerpoint, application/msword,   application/x-shockwave-flash, */* Accept-Language: bg Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0;   Windows NT 5.1; Q312461) Host: nakov:808 4 Connection: Keep-Alive
Hello Servlet – HTTP Response ,[object Object],[object Object],HTTP/1.1 200 OK Content-Length:  100 Date: Fri, 26 Mar 200 6  10:06:28 GMT Server: Apache-Coyote/1.1 <html><head> <title>Hello Servlet</title> </head><body> <h1>Hello, Nakov</h1> </body></html>
Image Counter Servlet ,[object Object],[object Object],[object Object],[object Object],[object Object]
Image Counter Servlet (2) import javax.servlet.*; import javax.servlet.http.*; ... public class ImageCounterServlet extends HttpServlet {  private String mStartDate;  private int mVisitCounter;  public void init() {  mStartDate = (new Date()).toString();  mVisitCounter = 0;  }  public BufferedImage createImage(String msg) { ... }
Image Counter Servlet (3) public void doGet(HttpServletRequest request,  HttpServletResponse response)  throws IOException, ServletException {  String msg;  synchronized(this) {  mVisitCounter++;  msg = &quot;&quot; + mVisitCounter + &quot; visits since &quot; + mStartDate;  }  BufferedImage image = createImage(msg);  response.setContentType(&quot;image/jpeg&quot;);  OutputStream out = response.getOutputStream(); // Encode the image in JPEG format and // write the image to the output stream   }  }
Image Counter Servlet in Action
Using Sessions
What is a Session? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sessions in Servlets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The Sessions API ,[object Object],[object Object],[object Object],[object Object],[object Object]
Getting The Session Object ,[object Object],[object Object],[object Object],[object Object],[object Object],HttpSession session = request.getSession();
Behind  T he Scenes  ,[object Object],[object Object],[object Object],[object Object],[object Object]
Extracting Data From  The  Session  ,[object Object],[object Object],[object Object],[object Object],[object Object],Integer accessCount = (Integer)   session.getAttribute(&quot;accessCount&quot;); Enumeration attributes = request.getAttributeNames();
Storing  Data  In   The  Session  ,[object Object],[object Object],HttpSession session = request.getSession(); session.setAttribute(&quot;name&quot;, &quot;Svetlin Nakov&quot;); session. remove Attribute(&quot;name&quot;);
Getting  Additional Session Information   ,[object Object],[object Object],[object Object],[object Object],public boolean isNew(); public String getId(); public long getLastAccessedTime(); public long getCreationTime();
Session Timeout ,[object Object],[object Object],[object Object],[object Object],public int getMaxInactiveInterval(); public void setMaxInactiveInterval (int seconds) ;
Terminating Sessions  ,[object Object],[object Object],[object Object],[object Object],public void invalidate() ;
Login / Logout – Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Login Form <html> <head><title>Login</title></head> <body> <form method=&quot;POST&quot; action=&quot;LoginServlet&quot;> Please login:<br> Username:  <input type=&quot;text&quot; name=&quot;username&quot;><br> Password:  <input type=&quot;password&quot; name=&quot;password&quot;><br> <input type=&quot;submit&quot; value=&quot;Login&quot;> </form> </body> </html> LoginForm.html
Login Servlet public class LoginServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String username =   req.getParameter(&quot;username&quot;); String password =   req.getParameter(&quot;password&quot;); PrintWriter out = resp.getWriter(); if (isLoginValid(username, password)) { HttpSession session = req.getSession(); session.setAttribute(&quot;USER&quot;, username); response.sendRedirect(&quot;MainServlet&quot;); } else { response.sendRedirect(&quot;InvalidLogin.html&quot;); } } } Login Servlet . java
Main Servlet public class MainServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = request.getSession(); String userName = (String)   s ession.getAttribute(&quot;USER&quot;); if (userName != null) { response.setContentType(&quot;text/html&quot;); ServletOutputStream out =   resp.getOutputStream(); out.println(&quot;<html> <body><h1> &quot;); out.println(&quot;Hello, &quot; + userName + &quot;! &quot;); out.println(&quot; </h1> </body></html>&quot;); } else { response.sendRedirect(&quot;LoginForm.html&quot;); } } } MainServlet.java
Logout Servlet public class LogoutServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); session.invalidate(); response.setContentType(&quot;text/html&quot;); ServletOutputStream out = response.getOutputStream(); out.println(&quot;<html><head>&quot;); out.println(&quot;<title>Logout</title></head>&quot;); out.println(&quot;<body>&quot;); out.println(&quot;<h1>Logout successfull.</h1>&quot;); out.println(&quot;</body></html>&quot;); } } LogoutServlet.java
Invalid Login Page <html> <head> <title>Error</title> </head> <body> <h1>Invalid login!</h1> Please <a href=&quot;LoginForm.html&quot;>try again</a>. </body> </html> InvalidLogin.html
The Browser's Cache Problems ,[object Object],[object Object],[object Object],[object Object],response.setHeader(&quot;Pragma&quot;, &quot;No-cache&quot;); response.setDateHeader(&quot;Expires&quot;, 0); response.setHeader(&quot;Cache-Control&quot;, &quot;no-cache&quot;);
Problems ,[object Object],[object Object],[object Object],[object Object]
Homework ,[object Object],[object Object],[object Object],[object Object],[object Object]
Homework (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

ADO .Net
ADO .Net ADO .Net
ADO .Net
DrSonali Vyas
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
sandeep54552
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
Hùng Nguyễn Huy
 
Java Collections
Java  Collections Java  Collections
Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
prabhu rajendran
 
Java swing
Java swingJava swing
Java swing
Apurbo Datta
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
Hitesh-Java
 
Express js
Express jsExpress js
Express js
Manav Prasad
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Kasun Madusanke
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
Andres Baravalle
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
VMahesh5
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
Dhruvin Nakrani
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
Jeff Fox
 
Servlets
ServletsServlets
Servlets
ServletsServlets
Servlets
Geethu Mohan
 

What's hot (20)

ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
Java swing
Java swingJava swing
Java swing
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Express js
Express jsExpress js
Express js
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Servlets
ServletsServlets
Servlets
 
Servlets
ServletsServlets
Servlets
 

Viewers also liked

Java Servlets
Java ServletsJava Servlets
Java Servlets
Nitin Pai
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
kamal kotecha
 
Java basic
Java basicJava basic
Java basic
Sonam Sharma
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
jaimefrozr
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
Eduonix Learning Solutions
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
Intelligo Technologies
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
mahir jain
 
Core java slides
Core java slidesCore java slides
Core java slides
Abhilash Nair
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Veerabadra Badra
 

Viewers also liked (11)

Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java servlet life cycle - methods ppt
Java servlet life cycle - methods pptJava servlet life cycle - methods ppt
Java servlet life cycle - methods ppt
 
Java basic
Java basicJava basic
Java basic
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
Core java slides
Core java slidesCore java slides
Core java slides
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 

Similar to Java Servlets

Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
Arumugam90
 
Servlet
Servlet Servlet
Servlet
Dhara Joshi
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
Ankit Minocha
 
Basics Of Servlet
Basics Of ServletBasics Of Servlet
Basics Of Servlet
Shubhani Jain
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
bharathiv53
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
ssbd6985
 
Servlets
ServletsServlets
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
Tanmoy Barman
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Tushar B Kute
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
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
 
Server-side Technologies in Java
Server-side Technologies in JavaServer-side Technologies in Java
Server-side Technologies in Java
Anirban Majumdar
 
18CSC311J Web Design and Development UNIT-3
18CSC311J Web Design and Development UNIT-318CSC311J Web Design and Development UNIT-3
18CSC311J Web Design and Development UNIT-3
sivakumarmcs
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
deepak kumar
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
Techglyphs
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
WebStackAcademy
 
Servlet by Rj
Servlet by RjServlet by Rj
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
team11vgnt
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
Eleonora Ciceri
 

Similar to Java Servlets (20)

Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
 
Servlet
Servlet Servlet
Servlet
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Basics Of Servlet
Basics Of ServletBasics Of Servlet
Basics Of Servlet
 
Http Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responsesHttp Server Programming in JAVA - Handling http requests and responses
Http Server Programming in JAVA - Handling http requests and responses
 
UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Servlets
ServletsServlets
Servlets
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 
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)
 
Server-side Technologies in Java
Server-side Technologies in JavaServer-side Technologies in Java
Server-side Technologies in Java
 
18CSC311J Web Design and Development UNIT-3
18CSC311J Web Design and Development UNIT-318CSC311J Web Design and Development UNIT-3
18CSC311J Web Design and Development UNIT-3
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
Dynamic content generation
Dynamic content generationDynamic content generation
Dynamic content generation
 

More from BG Java EE Course

Rich faces
Rich facesRich faces
Rich faces
BG Java EE Course
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
BG Java EE Course
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
BG Java EE Course
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
BG Java EE Course
 
JSTL
JSTLJSTL
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
BG Java EE Course
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
BG Java EE Course
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
BG Java EE Course
 
CSS
CSSCSS
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
BG Java EE Course
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
BG Java EE Course
 
WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
BG Java EE Course
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
BG Java EE Course
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
BG Java EE Course
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
BG Java EE Course
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
BG Java EE Course
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
BG Java EE Course
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
BG Java EE Course
 
Introduction to-RDBMS-systems
Introduction to-RDBMS-systemsIntroduction to-RDBMS-systems
Introduction to-RDBMS-systems
BG Java EE Course
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 

More from BG Java EE Course (20)

Rich faces
Rich facesRich faces
Rich faces
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
JSTL
JSTLJSTL
JSTL
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
CSS
CSSCSS
CSS
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 
WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Introduction to-RDBMS-systems
Introduction to-RDBMS-systemsIntroduction to-RDBMS-systems
Introduction to-RDBMS-systems
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 

Recently uploaded

So You've Lost Quorum: Lessons From Accidental Downtime
So You've Lost Quorum: Lessons From Accidental DowntimeSo You've Lost Quorum: Lessons From Accidental Downtime
So You've Lost Quorum: Lessons From Accidental Downtime
ScyllaDB
 
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
zjhamm304
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
AlexanderRichford
 
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time MLMongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
ScyllaDB
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
Multivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back againMultivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back again
Kieran Kunhya
 
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
anilsa9823
 
Guidelines for Effective Data Visualization
Guidelines for Effective Data VisualizationGuidelines for Effective Data Visualization
Guidelines for Effective Data Visualization
UmmeSalmaM1
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
leebarnesutopia
 
An All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS MarketAn All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS Market
ScyllaDB
 
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google CloudRadically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
ScyllaDB
 
CNSCon 2024 Lightning Talk: Don’t Make Me Impersonate My Identity
CNSCon 2024 Lightning Talk: Don’t Make Me Impersonate My IdentityCNSCon 2024 Lightning Talk: Don’t Make Me Impersonate My Identity
CNSCon 2024 Lightning Talk: Don’t Make Me Impersonate My Identity
Cynthia Thomas
 
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDBScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
Real-Time Persisted Events at Supercell
Real-Time Persisted Events at  SupercellReal-Time Persisted Events at  Supercell
Real-Time Persisted Events at Supercell
ScyllaDB
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - MydbopsMySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
ScyllaDB Real-Time Event Processing with CDC
ScyllaDB Real-Time Event Processing with CDCScyllaDB Real-Time Event Processing with CDC
ScyllaDB Real-Time Event Processing with CDC
ScyllaDB
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
An Introduction to All Data Enterprise Integration
An Introduction to All Data Enterprise IntegrationAn Introduction to All Data Enterprise Integration
An Introduction to All Data Enterprise Integration
Safe Software
 

Recently uploaded (20)

So You've Lost Quorum: Lessons From Accidental Downtime
So You've Lost Quorum: Lessons From Accidental DowntimeSo You've Lost Quorum: Lessons From Accidental Downtime
So You've Lost Quorum: Lessons From Accidental Downtime
 
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...QA or the Highway - Component Testing: Bridging the gap between frontend appl...
QA or the Highway - Component Testing: Bridging the gap between frontend appl...
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
 
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time MLMongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
MongoDB vs ScyllaDB: Tractian’s Experience with Real-Time ML
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
Multivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back againMultivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back again
 
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
Call Girls Chennai ☎️ +91-7426014248 😍 Chennai Call Girl Beauty Girls Chennai...
 
Guidelines for Effective Data Visualization
Guidelines for Effective Data VisualizationGuidelines for Effective Data Visualization
Guidelines for Effective Data Visualization
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
 
An All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS MarketAn All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS Market
 
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google CloudRadically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
Radically Outperforming DynamoDB @ Digital Turbine with SADA and Google Cloud
 
CNSCon 2024 Lightning Talk: Don’t Make Me Impersonate My Identity
CNSCon 2024 Lightning Talk: Don’t Make Me Impersonate My IdentityCNSCon 2024 Lightning Talk: Don’t Make Me Impersonate My Identity
CNSCon 2024 Lightning Talk: Don’t Make Me Impersonate My Identity
 
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDBScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
Real-Time Persisted Events at Supercell
Real-Time Persisted Events at  SupercellReal-Time Persisted Events at  Supercell
Real-Time Persisted Events at Supercell
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - MydbopsMySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
 
ScyllaDB Real-Time Event Processing with CDC
ScyllaDB Real-Time Event Processing with CDCScyllaDB Real-Time Event Processing with CDC
ScyllaDB Real-Time Event Processing with CDC
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
 
An Introduction to All Data Enterprise Integration
An Introduction to All Data Enterprise IntegrationAn Introduction to All Data Enterprise Integration
An Introduction to All Data Enterprise Integration
 

Java Servlets

  • 1. Java Servlets Svetlin Nakov Borislava Spasova
  • 2.
  • 3.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Java Servlets Technical Architecture
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 26.
  • 27.
  • 28. Hello Servlet – Example public void doGet(HttpServletRequest r equest, HttpServletResponse r esponse) throws ServletException, IOException { r esponse.setContentType(&quot;text/html&quot;); ServletOutputStream out = r esponse.getOutputStream(); String userName = r equest.getParameter(&quot;user_name&quot;); out.println(&quot;<html> <head> &quot;); out.println(&quot;<title>Hello Servlet</title>&quot;); out.println(&quot;</head><body>&quot;); out.println(&quot;<h1>Hello, &quot; + userName + &quot;</h1>&quot;); out.println(&quot;</body></html>&quot;); } Hello Servlet . java
  • 29.
  • 30.
  • 32.
  • 33.
  • 34.
  • 35. Image Counter Servlet (2) import javax.servlet.*; import javax.servlet.http.*; ... public class ImageCounterServlet extends HttpServlet { private String mStartDate; private int mVisitCounter; public void init() { mStartDate = (new Date()).toString(); mVisitCounter = 0; } public BufferedImage createImage(String msg) { ... }
  • 36. Image Counter Servlet (3) public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String msg; synchronized(this) { mVisitCounter++; msg = &quot;&quot; + mVisitCounter + &quot; visits since &quot; + mStartDate; } BufferedImage image = createImage(msg); response.setContentType(&quot;image/jpeg&quot;); OutputStream out = response.getOutputStream(); // Encode the image in JPEG format and // write the image to the output stream } }
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50. Login Form <html> <head><title>Login</title></head> <body> <form method=&quot;POST&quot; action=&quot;LoginServlet&quot;> Please login:<br> Username: <input type=&quot;text&quot; name=&quot;username&quot;><br> Password: <input type=&quot;password&quot; name=&quot;password&quot;><br> <input type=&quot;submit&quot; value=&quot;Login&quot;> </form> </body> </html> LoginForm.html
  • 51. Login Servlet public class LoginServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String username = req.getParameter(&quot;username&quot;); String password = req.getParameter(&quot;password&quot;); PrintWriter out = resp.getWriter(); if (isLoginValid(username, password)) { HttpSession session = req.getSession(); session.setAttribute(&quot;USER&quot;, username); response.sendRedirect(&quot;MainServlet&quot;); } else { response.sendRedirect(&quot;InvalidLogin.html&quot;); } } } Login Servlet . java
  • 52. Main Servlet public class MainServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = request.getSession(); String userName = (String) s ession.getAttribute(&quot;USER&quot;); if (userName != null) { response.setContentType(&quot;text/html&quot;); ServletOutputStream out = resp.getOutputStream(); out.println(&quot;<html> <body><h1> &quot;); out.println(&quot;Hello, &quot; + userName + &quot;! &quot;); out.println(&quot; </h1> </body></html>&quot;); } else { response.sendRedirect(&quot;LoginForm.html&quot;); } } } MainServlet.java
  • 53. Logout Servlet public class LogoutServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); session.invalidate(); response.setContentType(&quot;text/html&quot;); ServletOutputStream out = response.getOutputStream(); out.println(&quot;<html><head>&quot;); out.println(&quot;<title>Logout</title></head>&quot;); out.println(&quot;<body>&quot;); out.println(&quot;<h1>Logout successfull.</h1>&quot;); out.println(&quot;</body></html>&quot;); } } LogoutServlet.java
  • 54. Invalid Login Page <html> <head> <title>Error</title> </head> <body> <h1>Invalid login!</h1> Please <a href=&quot;LoginForm.html&quot;>try again</a>. </body> </html> InvalidLogin.html
  • 55.
  • 56.
  • 57.
  • 58.

Editor's Notes

  1. ## * * 07/16/96
  2. ## * * 07/16/96
  3. ## * * 07/16/96 Example of HTTP GET: Google search Example of HTTP POST: Login page
  4. ## * * 07/16/96
  5. ## * * 07/16/96
  6. ## * * 07/16/96
  7. ## * * 07/16/96
  8. Note: As of Servlet 2.2, the getValue() method is now deprecated. Use getAttribute() instead.
  9. Note: As of Servlet 2.2, the getValue() method is now deprecated. Use getAttribute() instead.
  翻译: