SlideShare una empresa de Scribd logo
1 de 25
PHP vs. JSP
Hello World - JSP <HTML> <HEAD> <TITLE>JSP -- Hello World!</TITLE> </HEAD> <BODY> &nbsp; <% out.println(&quot; Hello World&quot;); %>   ! </BODY> </HTML>
Hello World - PHP <HTML> <HEAD> <TITLE>PHP – Hello World!</TITLE> </HEAD> <BODY> <CENTER> <FONT COLOR=RED SIZE=5> &nbsp; <?php echo &quot;Hello world!&quot;;?>   ! </FONT> </CENTER> </BODY> </HTML>
JSP – Print date as dd/MM/yyyy <HTML> <HEAD> <TITLE>JSP -- Hello World!</TITLE> </HEAD> <BODY> <% java.util.Calendar cal = java.util.Calendar.getInstance(); out.println( new  SimpleDateFormat(“dd/MM/yyyy).format (cal.getTime()‏) );  %>   </BODY> </HTML>
PHP – Print Date as dd/MM/yyyy <HTML> <HEAD> <TITLE>PHP – Hello World!</TITLE> </HEAD> <BODY> <CENTER> <FONT COLOR=RED SIZE=5> &nbsp; <?php echo date(“d/m/Y”)?>   ! </FONT> </CENTER> </BODY> </HTML>
JSP – Handling Forms The form: <html> <body> <form action=&quot;welcome.jsp&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;name&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /> </form> </body> </html> Handler: <html> <body> Welcome  <%request.getParameter(&quot;name”)%> .<br /> You are  <%request.getParameter(&quot;age”)%>  years old. </body> </html>
PHP – Handling Forms The form: <html> <body> <form action=&quot;welcome.php&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;name&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /> </form> </body> </html> Handler: <html> <body> Welcome  <?php echo $_REQUEST[&quot;name&quot;]; ?> .<br /> You are  <?php echo $_REQUEST[&quot;age&quot;]; ?>  years old. </body> </html>
JSP - Session <html> <body>   <% //Get current session or create a new session HtppSession session = request.getSession(true);  //Add information to the session session.setAttribute(“name”, “Pramati”); //Print the information out.println(session.getAttribute(“name”); %> </body> </html>
PHP - Session //Getting or starting a new session <?php session_start(); ?> <html> <body>   <?php //Add information to the session $_SESSION['name']= “Pramati”; //Print the information echo $_SESSION['name'];   ?> </body> </html>
JSP – Mail Form <HTML> <FORM METHOD=POST ACTION=”mailform.jsp”> SMTP SERVER: <INPUT TYPE=&quot;text&quot; NAME=&quot;p_smtpServer&quot; SIZE=60 VALUE=&quot;<%= l_svr!=null ? l_svr : &quot;&quot; %>&quot; > TO: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME=&quot;p_to&quot;> FROM: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME=&quot;p_bcc&quot;> SUBJECT: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=100 NAME=&quot;p_subject&quot;> MESSAGE:<br>   <TEXTAREA NAME=&quot;p_message&quot; ROWS=10 COLS=66 SIZE=2000 WRAP=HARD>   </TEXTAREA>   <INPUT TYPE='SUBMIT'>   </FORM> </HTML>
JSP – Mail Sender <html>  <jsp:useBean id=&quot;sendMail&quot; class=&quot;SendMailBean&quot; scope=&quot;page&quot; /> <% String l_from  =  request.getParameter (&quot;p_from&quot;);   String l_to  =  request.getParameter (&quot;p_to&quot;);   String l_cc  =  request.getParameter (&quot;p_cc&quot;);   String l_subject =  request.getParameter (&quot;p_subject&quot;);   String l_message =  request.getParameter (&quot;p_message&quot;);   %>   <%= sendMail.send(l_from, l_to, l_cc, l_subject, l_message) %> </html>
JSP – Mail sender bean – Page 1 import javax.mail.*;  //JavaMail packages import javax.mail.internet.*; //JavaMail Internet packages import java.util.*;  //Java Util packages public class SendMailBean { public String send(String p_from, String p_to, String p_subject, String p_message, String p_smtpServer) { // Gets the System properties Properties l_props = System.getProperties(); // Puts the SMTP server name to properties object   l_props.put(&quot;mail.smtp.host&quot;,p_smtpServer); // Get the default Session using Properties Object Session l_session = Session.getDefaultInstance(l_props, null); l_session.setDebug(true); // Enable the debug mode
JSP – Mail sender bean – Page 2 try {   MimeMessage l_msg = new MimeMessage(l_session); // Create a New message   l_msg.setFrom(new InternetAddress(p_from)); // Set the From address   l_msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(p_to, false));   l_msg.setSubject(p_subject); // Sets the Subject   MimeBodyPart l_mbp = new MimeBodyPart();   l_mbp.setText(p_message);   // Create the Multipart and its parts to it   Multipart l_mp = new MimeMultipart();   l_mp.addBodyPart(l_mbp);   // Add the Multipart to the message   l_msg.setContent(l_mp);   // Set the Date: header   l_msg.setSentDate(new Date());
JSP – Mail sender bean – Page 3   // Send the message   Transport.send(l_msg);   // If here, then message is successfully sent.   // Display Success message   return “Mail sent”; } catch (Exception e) { return “Mail failed”; }
PHP – Mail form <HTML> <FORM METHOD=POST ACTION=”mailform.php”> TO: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME=&quot;p_to&quot;> SUBJECT: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=100 NAME=&quot;p_subject&quot;> MESSAGE:<br>   <TEXTAREA NAME=&quot;p_message&quot; ROWS=10 COLS=66 SIZE=2000 WRAP=HARD>   </TEXTAREA>   <INPUT TYPE='SUBMIT'>   </FORM> </HTML>
PHP – Mail Sender <?php //send email $email = $_REQUEST['email'] ;  $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( &quot;someone@example.com&quot;, &quot;Subject: $subject&quot;,  $message, &quot;From: $email&quot; ); echo &quot;Thank you for using our mail form&quot;; ?>
JSP – File Upload Form Note: No in-built support. Should rely on libraries. This example uses Apache's commons-upload lib. <HTML> <HEAD> <META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=windows-1252&quot;/> <TITLE>File Upload Page</TITLE> </HEAD> <BODY>Upload Files <FORM name=&quot;filesForm&quot; action=&quot;ProcessFileUpload.jsp&quot;   method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;> File 1:<input type=&quot;file&quot; name=&quot;file1&quot;/><br/>   <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Upload File&quot;/> </FORM> </BODY> </HTML>
JSP – File Upload <html> <body> <% if(ServletFileUpload.isMultipartContent(request))‏ { FileItemFactory factory = new DiskFileItemFactory();   ServletFileUpload upload = new ServletFileUpload(factory);   List items = upload.parseRequest(request);   Iterator itemsIter = items.getIterator();   if(iter.hasNext())‏   { File uploadedFile = new File(item.getName());  item.write(uploadedFile);    } } %> </body> </html>
PHP File Upload Form <HTML> <HEAD> <META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=windows-1252&quot;/> <TITLE>File Upload Page</TITLE> </HEAD> <BODY>Upload Files <FORM name=&quot;filesForm&quot; action=&quot;ProcessFileUpload.php&quot;   method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;>   File 1:<input type=&quot;file&quot; name=&quot;file1&quot;/><br/>   <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Upload File&quot;/> </FORM> </BODY> </HTML>
PHP – File Upload <?php if ($_FILES[&quot;file&quot;][&quot;error&quot;] > 0)‏ { echo &quot;Return Code: &quot; . $_FILES[&quot;file&quot;][&quot;error&quot;] . &quot;<br />&quot;; } else { move_uploaded_file($_FILES[&quot;file&quot;][&quot;tmp_name&quot;],  &quot;upload/&quot; . $_FILES[&quot;file&quot;][&quot;name&quot;]); echo &quot;Stored in: &quot; . &quot;upload/&quot; . $_FILES[&quot;file&quot;][&quot;name&quot;]; } } ?>
JSP and Database - I <%@ page import=&quot;java.sql.*&quot; %> <HTML> <HEAD> <TITLE>Employee List</TITLE> </HEAD> <BODY> <TABLE BORDER=1 width=&quot;75%&quot;> <TR> <TH>Last Name</TH><TH>First Name</TH> </TR> <% //Connection conn = null; java.sql.Connection conn= null; Statement st = null; ResultSet rs = null;
JSP and Database - II try { // Class.forName(&quot;com.mysql.jdbc.Driver&quot;).newInstance(); Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;).newInstance(); conn = DriverManager.getConnection( &quot;jdbc:mysql://localhost/jsp?user=xxx&password=xxx&quot;); st = conn.createStatement(); rs = st.executeQuery(&quot;select * from employees&quot;); while(rs.next()) { %> <TR><TD><%= rs.getString(&quot;lname_txt&quot;) %></TD> <TD><%= rs.getString(&quot;fname_txt&quot;) %></TD></TR> <% } %> </TABLE>
JSP and Database - III <% } catch (Exception ex) { ex.printStackTrace(); %> </TABLE> Ooops, something bad happened: <% } finally { if (rs != null) rs.close(); if (st != null) st.close(); if (conn != null) conn.close(); } %> </BODY> </HTML>
PHP and Database - I <? $username=&quot;username&quot;; $password=&quot;password&quot;; $database=&quot;your_database&quot;; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( &quot;Unable to select database&quot;); $query=&quot;SELECT * FROM contacts&quot;; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close();
PHP and Database - II echo &quot;<b><center>Database Output</center></b><br><br>&quot;; $i=0; while ($i < $num) { $first=mysql_result($result,$i,&quot;first&quot;); $last=mysql_result($result,$i,&quot;last&quot;); $phone=mysql_result($result,$i,&quot;phone&quot;); $mobile=mysql_result($result,$i,&quot;mobile&quot;); $fax=mysql_result($result,$i,&quot;fax&quot;); $email=mysql_result($result,$i,&quot;email&quot;); $web=mysql_result($result,$i,&quot;web&quot;); echo &quot;<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail:  $email<br>Web: $web<br><hr><br>&quot;; $i++; } ?>

Más contenido relacionado

La actualidad más candente

開放源碼電子書與EPUB幕後排版
開放源碼電子書與EPUB幕後排版開放源碼電子書與EPUB幕後排版
開放源碼電子書與EPUB幕後排版Kyle Lin
 
Computer Networks: An Introduction
Computer Networks: An IntroductionComputer Networks: An Introduction
Computer Networks: An Introductionsanand0
 
Http header的方方面面
Http header的方方面面Http header的方方面面
Http header的方方面面Tony Deng
 
Advanced SEO for Web Developers
Advanced SEO for Web DevelopersAdvanced SEO for Web Developers
Advanced SEO for Web DevelopersNathan Buggia
 
Making sense of users' Web activities
Making sense of users' Web activitiesMaking sense of users' Web activities
Making sense of users' Web activitiesMathieu d'Aquin
 
Sphinx 1.1 i18n 機能紹介
Sphinx 1.1 i18n 機能紹介Sphinx 1.1 i18n 機能紹介
Sphinx 1.1 i18n 機能紹介Ian Lewis
 
LinkedIn Platform at LeWeb 2010
LinkedIn Platform at LeWeb 2010LinkedIn Platform at LeWeb 2010
LinkedIn Platform at LeWeb 2010Adam Trachtenberg
 
.htaccess for SEOs - A presentation by Roxana Stingu
.htaccess for SEOs - A presentation by Roxana Stingu.htaccess for SEOs - A presentation by Roxana Stingu
.htaccess for SEOs - A presentation by Roxana StinguRoxana Stingu
 

La actualidad más candente (12)

Phpwebdevelping
PhpwebdevelpingPhpwebdevelping
Phpwebdevelping
 
開放源碼電子書與EPUB幕後排版
開放源碼電子書與EPUB幕後排版開放源碼電子書與EPUB幕後排版
開放源碼電子書與EPUB幕後排版
 
Computer Networks: An Introduction
Computer Networks: An IntroductionComputer Networks: An Introduction
Computer Networks: An Introduction
 
Http header的方方面面
Http header的方方面面Http header的方方面面
Http header的方方面面
 
Advanced SEO for Web Developers
Advanced SEO for Web DevelopersAdvanced SEO for Web Developers
Advanced SEO for Web Developers
 
Lect_html1
Lect_html1Lect_html1
Lect_html1
 
Making sense of users' Web activities
Making sense of users' Web activitiesMaking sense of users' Web activities
Making sense of users' Web activities
 
Sphinx 1.1 i18n 機能紹介
Sphinx 1.1 i18n 機能紹介Sphinx 1.1 i18n 機能紹介
Sphinx 1.1 i18n 機能紹介
 
LinkedIn Platform at LeWeb 2010
LinkedIn Platform at LeWeb 2010LinkedIn Platform at LeWeb 2010
LinkedIn Platform at LeWeb 2010
 
Introduction to python scrapping
Introduction to python scrappingIntroduction to python scrapping
Introduction to python scrapping
 
PHP 5 Sucks. PHP 5 Rocks.
PHP 5 Sucks. PHP 5 Rocks.PHP 5 Sucks. PHP 5 Rocks.
PHP 5 Sucks. PHP 5 Rocks.
 
.htaccess for SEOs - A presentation by Roxana Stingu
.htaccess for SEOs - A presentation by Roxana Stingu.htaccess for SEOs - A presentation by Roxana Stingu
.htaccess for SEOs - A presentation by Roxana Stingu
 

Destacado

Destacado (20)

Sàlix i els sentits
Sàlix i els sentitsSàlix i els sentits
Sàlix i els sentits
 
apostila yorubá
apostila yorubáapostila yorubá
apostila yorubá
 
Roupas Jumps
Roupas JumpsRoupas Jumps
Roupas Jumps
 
Prometete
PrometetePrometete
Prometete
 
diir-press-kit
diir-press-kitdiir-press-kit
diir-press-kit
 
Recordes?
Recordes?Recordes?
Recordes?
 
PresentacióN Tema IX
PresentacióN Tema  IXPresentacióN Tema  IX
PresentacióN Tema IX
 
misión y visión
misión y visiónmisión y visión
misión y visión
 
Artigo como escolher seu coach
Artigo como escolher seu coachArtigo como escolher seu coach
Artigo como escolher seu coach
 
Novo Plano da BBOM
Novo Plano da BBOMNovo Plano da BBOM
Novo Plano da BBOM
 
Missa mãe
Missa mãeMissa mãe
Missa mãe
 
Feliz navidad
Feliz navidadFeliz navidad
Feliz navidad
 
Bienvenido a su clase de historia de honduras
Bienvenido a su clase de historia de hondurasBienvenido a su clase de historia de honduras
Bienvenido a su clase de historia de honduras
 
IT NEWS
IT NEWSIT NEWS
IT NEWS
 
L´Aigua
L´AiguaL´Aigua
L´Aigua
 
CAN 2008 - quelques images
CAN 2008 - quelques imagesCAN 2008 - quelques images
CAN 2008 - quelques images
 
webdynpro Application attach in Menu
webdynpro Application attach in Menuwebdynpro Application attach in Menu
webdynpro Application attach in Menu
 
Trabalho de geografia (1)
Trabalho de geografia (1)Trabalho de geografia (1)
Trabalho de geografia (1)
 
Resumosocio
ResumosocioResumosocio
Resumosocio
 
Pagina 1
Pagina 1Pagina 1
Pagina 1
 

Similar a Phpvsjsp

PHP Presentation
PHP PresentationPHP Presentation
PHP PresentationNikhil Jain
 
YL Intro html
YL Intro htmlYL Intro html
YL Intro htmldilom1986
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Coursemussawir20
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7phuphax
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To LampAmzad Hossain
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operatorsmussawir20
 
The Basics Of Page Creation
The Basics Of Page CreationThe Basics Of Page Creation
The Basics Of Page CreationWildan Maulana
 
Java Script
Java ScriptJava Script
Java Scriptsiddaram
 
PHP Presentation
PHP PresentationPHP Presentation
PHP PresentationAnkush Jain
 
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructurePamela Fox
 
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructureguest517f2f
 
Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)Michiel Rook
 
PHPTAL introduction
PHPTAL introductionPHPTAL introduction
PHPTAL introduction'"">
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Securitymussawir20
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP yucefmerhi
 

Similar a Phpvsjsp (20)

Lecture3
Lecture3Lecture3
Lecture3
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Php 3 1
Php 3 1Php 3 1
Php 3 1
 
YL Intro html
YL Intro htmlYL Intro html
YL Intro html
 
Php
PhpPhp
Php
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7KMUTNB - Internet Programming 3/7
KMUTNB - Internet Programming 3/7
 
Introduction To Lamp
Introduction To LampIntroduction To Lamp
Introduction To Lamp
 
Php Calling Operators
Php Calling OperatorsPhp Calling Operators
Php Calling Operators
 
The Basics Of Page Creation
The Basics Of Page CreationThe Basics Of Page Creation
The Basics Of Page Creation
 
Java Script
Java ScriptJava Script
Java Script
 
Web development
Web developmentWeb development
Web development
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Intro Html
Intro HtmlIntro Html
Intro Html
 
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
 
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google InfrastructureLiving in the Cloud: Hosting Data & Apps Using the Google Infrastructure
Living in the Cloud: Hosting Data & Apps Using the Google Infrastructure
 
Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)Phing - A PHP Build Tool (An Introduction)
Phing - A PHP Build Tool (An Introduction)
 
PHPTAL introduction
PHPTAL introductionPHPTAL introduction
PHPTAL introduction
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
 
Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP Lecture 3 - Comm Lab: Web @ ITP
Lecture 3 - Comm Lab: Web @ ITP
 

Último

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Phpvsjsp

  • 2. Hello World - JSP <HTML> <HEAD> <TITLE>JSP -- Hello World!</TITLE> </HEAD> <BODY> &nbsp; <% out.println(&quot; Hello World&quot;); %> ! </BODY> </HTML>
  • 3. Hello World - PHP <HTML> <HEAD> <TITLE>PHP – Hello World!</TITLE> </HEAD> <BODY> <CENTER> <FONT COLOR=RED SIZE=5> &nbsp; <?php echo &quot;Hello world!&quot;;?> ! </FONT> </CENTER> </BODY> </HTML>
  • 4. JSP – Print date as dd/MM/yyyy <HTML> <HEAD> <TITLE>JSP -- Hello World!</TITLE> </HEAD> <BODY> <% java.util.Calendar cal = java.util.Calendar.getInstance(); out.println( new SimpleDateFormat(“dd/MM/yyyy).format (cal.getTime()‏) ); %> </BODY> </HTML>
  • 5. PHP – Print Date as dd/MM/yyyy <HTML> <HEAD> <TITLE>PHP – Hello World!</TITLE> </HEAD> <BODY> <CENTER> <FONT COLOR=RED SIZE=5> &nbsp; <?php echo date(“d/m/Y”)?> ! </FONT> </CENTER> </BODY> </HTML>
  • 6. JSP – Handling Forms The form: <html> <body> <form action=&quot;welcome.jsp&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;name&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /> </form> </body> </html> Handler: <html> <body> Welcome <%request.getParameter(&quot;name”)%> .<br /> You are <%request.getParameter(&quot;age”)%> years old. </body> </html>
  • 7. PHP – Handling Forms The form: <html> <body> <form action=&quot;welcome.php&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;name&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /> </form> </body> </html> Handler: <html> <body> Welcome <?php echo $_REQUEST[&quot;name&quot;]; ?> .<br /> You are <?php echo $_REQUEST[&quot;age&quot;]; ?> years old. </body> </html>
  • 8. JSP - Session <html> <body> <% //Get current session or create a new session HtppSession session = request.getSession(true); //Add information to the session session.setAttribute(“name”, “Pramati”); //Print the information out.println(session.getAttribute(“name”); %> </body> </html>
  • 9. PHP - Session //Getting or starting a new session <?php session_start(); ?> <html> <body> <?php //Add information to the session $_SESSION['name']= “Pramati”; //Print the information echo $_SESSION['name']; ?> </body> </html>
  • 10. JSP – Mail Form <HTML> <FORM METHOD=POST ACTION=”mailform.jsp”> SMTP SERVER: <INPUT TYPE=&quot;text&quot; NAME=&quot;p_smtpServer&quot; SIZE=60 VALUE=&quot;<%= l_svr!=null ? l_svr : &quot;&quot; %>&quot; > TO: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME=&quot;p_to&quot;> FROM: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME=&quot;p_bcc&quot;> SUBJECT: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=100 NAME=&quot;p_subject&quot;> MESSAGE:<br> <TEXTAREA NAME=&quot;p_message&quot; ROWS=10 COLS=66 SIZE=2000 WRAP=HARD> </TEXTAREA> <INPUT TYPE='SUBMIT'>   </FORM> </HTML>
  • 11. JSP – Mail Sender <html> <jsp:useBean id=&quot;sendMail&quot; class=&quot;SendMailBean&quot; scope=&quot;page&quot; /> <% String l_from = request.getParameter (&quot;p_from&quot;); String l_to = request.getParameter (&quot;p_to&quot;); String l_cc = request.getParameter (&quot;p_cc&quot;); String l_subject = request.getParameter (&quot;p_subject&quot;); String l_message = request.getParameter (&quot;p_message&quot;); %> <%= sendMail.send(l_from, l_to, l_cc, l_subject, l_message) %> </html>
  • 12. JSP – Mail sender bean – Page 1 import javax.mail.*; //JavaMail packages import javax.mail.internet.*; //JavaMail Internet packages import java.util.*; //Java Util packages public class SendMailBean { public String send(String p_from, String p_to, String p_subject, String p_message, String p_smtpServer) { // Gets the System properties Properties l_props = System.getProperties(); // Puts the SMTP server name to properties object l_props.put(&quot;mail.smtp.host&quot;,p_smtpServer); // Get the default Session using Properties Object Session l_session = Session.getDefaultInstance(l_props, null); l_session.setDebug(true); // Enable the debug mode
  • 13. JSP – Mail sender bean – Page 2 try { MimeMessage l_msg = new MimeMessage(l_session); // Create a New message l_msg.setFrom(new InternetAddress(p_from)); // Set the From address l_msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(p_to, false)); l_msg.setSubject(p_subject); // Sets the Subject MimeBodyPart l_mbp = new MimeBodyPart(); l_mbp.setText(p_message); // Create the Multipart and its parts to it Multipart l_mp = new MimeMultipart(); l_mp.addBodyPart(l_mbp); // Add the Multipart to the message l_msg.setContent(l_mp); // Set the Date: header l_msg.setSentDate(new Date());
  • 14. JSP – Mail sender bean – Page 3 // Send the message Transport.send(l_msg); // If here, then message is successfully sent. // Display Success message return “Mail sent”; } catch (Exception e) { return “Mail failed”; }
  • 15. PHP – Mail form <HTML> <FORM METHOD=POST ACTION=”mailform.php”> TO: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=200 NAME=&quot;p_to&quot;> SUBJECT: <INPUT TYPE=TEXT SIZE=60 MAXLENGTH=100 NAME=&quot;p_subject&quot;> MESSAGE:<br> <TEXTAREA NAME=&quot;p_message&quot; ROWS=10 COLS=66 SIZE=2000 WRAP=HARD> </TEXTAREA> <INPUT TYPE='SUBMIT'>   </FORM> </HTML>
  • 16. PHP – Mail Sender <?php //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( &quot;someone@example.com&quot;, &quot;Subject: $subject&quot;, $message, &quot;From: $email&quot; ); echo &quot;Thank you for using our mail form&quot;; ?>
  • 17. JSP – File Upload Form Note: No in-built support. Should rely on libraries. This example uses Apache's commons-upload lib. <HTML> <HEAD> <META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=windows-1252&quot;/> <TITLE>File Upload Page</TITLE> </HEAD> <BODY>Upload Files <FORM name=&quot;filesForm&quot; action=&quot;ProcessFileUpload.jsp&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;> File 1:<input type=&quot;file&quot; name=&quot;file1&quot;/><br/> <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Upload File&quot;/> </FORM> </BODY> </HTML>
  • 18. JSP – File Upload <html> <body> <% if(ServletFileUpload.isMultipartContent(request))‏ { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = upload.parseRequest(request); Iterator itemsIter = items.getIterator(); if(iter.hasNext())‏ { File uploadedFile = new File(item.getName()); item.write(uploadedFile); } } %> </body> </html>
  • 19. PHP File Upload Form <HTML> <HEAD> <META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=windows-1252&quot;/> <TITLE>File Upload Page</TITLE> </HEAD> <BODY>Upload Files <FORM name=&quot;filesForm&quot; action=&quot;ProcessFileUpload.php&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;> File 1:<input type=&quot;file&quot; name=&quot;file1&quot;/><br/> <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Upload File&quot;/> </FORM> </BODY> </HTML>
  • 20. PHP – File Upload <?php if ($_FILES[&quot;file&quot;][&quot;error&quot;] > 0)‏ { echo &quot;Return Code: &quot; . $_FILES[&quot;file&quot;][&quot;error&quot;] . &quot;<br />&quot;; } else { move_uploaded_file($_FILES[&quot;file&quot;][&quot;tmp_name&quot;], &quot;upload/&quot; . $_FILES[&quot;file&quot;][&quot;name&quot;]); echo &quot;Stored in: &quot; . &quot;upload/&quot; . $_FILES[&quot;file&quot;][&quot;name&quot;]; } } ?>
  • 21. JSP and Database - I <%@ page import=&quot;java.sql.*&quot; %> <HTML> <HEAD> <TITLE>Employee List</TITLE> </HEAD> <BODY> <TABLE BORDER=1 width=&quot;75%&quot;> <TR> <TH>Last Name</TH><TH>First Name</TH> </TR> <% //Connection conn = null; java.sql.Connection conn= null; Statement st = null; ResultSet rs = null;
  • 22. JSP and Database - II try { // Class.forName(&quot;com.mysql.jdbc.Driver&quot;).newInstance(); Class.forName(&quot;org.gjt.mm.mysql.Driver&quot;).newInstance(); conn = DriverManager.getConnection( &quot;jdbc:mysql://localhost/jsp?user=xxx&password=xxx&quot;); st = conn.createStatement(); rs = st.executeQuery(&quot;select * from employees&quot;); while(rs.next()) { %> <TR><TD><%= rs.getString(&quot;lname_txt&quot;) %></TD> <TD><%= rs.getString(&quot;fname_txt&quot;) %></TD></TR> <% } %> </TABLE>
  • 23. JSP and Database - III <% } catch (Exception ex) { ex.printStackTrace(); %> </TABLE> Ooops, something bad happened: <% } finally { if (rs != null) rs.close(); if (st != null) st.close(); if (conn != null) conn.close(); } %> </BODY> </HTML>
  • 24. PHP and Database - I <? $username=&quot;username&quot;; $password=&quot;password&quot;; $database=&quot;your_database&quot;; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( &quot;Unable to select database&quot;); $query=&quot;SELECT * FROM contacts&quot;; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close();
  • 25. PHP and Database - II echo &quot;<b><center>Database Output</center></b><br><br>&quot;; $i=0; while ($i < $num) { $first=mysql_result($result,$i,&quot;first&quot;); $last=mysql_result($result,$i,&quot;last&quot;); $phone=mysql_result($result,$i,&quot;phone&quot;); $mobile=mysql_result($result,$i,&quot;mobile&quot;); $fax=mysql_result($result,$i,&quot;fax&quot;); $email=mysql_result($result,$i,&quot;email&quot;); $web=mysql_result($result,$i,&quot;web&quot;); echo &quot;<b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>&quot;; $i++; } ?>