0% found this document useful (0 votes)
8 views5 pages

WebTech UNIT - 3 Notes

The document discusses server-side scripting, focusing on PHP and Java-based technologies like JSP and Servlets. It covers PHP syntax, data types, and session handling, as well as the lifecycle and deployment of Servlets. The content emphasizes the importance of these technologies in creating dynamic and interactive web applications.

Uploaded by

pandeyshashwat15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

WebTech UNIT - 3 Notes

The document discusses server-side scripting, focusing on PHP and Java-based technologies like JSP and Servlets. It covers PHP syntax, data types, and session handling, as well as the lifecycle and deployment of Servlets. The content emphasizes the importance of these technologies in creating dynamic and interactive web applications.

Uploaded by

pandeyshashwat15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

‭OnedayStudy WebTech‬‭Visit‬

‭ nit 3: Server-Side Scripting & PHP‬


U
‭Development‬
‭1. Server-Side Scripting‬
‭ erver-side scripting refers to programs executed on a web server to generate dynamic web‬
S
‭content. Unlike client-side scripts that run in the browser (like JavaScript), server-side scripts‬


‭process requests, access databases, and return responses to users.‬

dy
‭Common Server-Side Scripting Languages:‬

‭‬
● ‭ HP‬‭– Open-source, widely used for web applications.‬
P
‭●‬ ‭CGI (Common Gateway Interface)‬‭– Used to execute scripts‬‭on a web server.‬

tu
‭●‬ ‭JSP (Java Server Pages)‬‭– Uses Java to create dynamic‬‭web pages.‬
‭●‬ ‭ASP.NET‬‭– Developed by Microsoft for web applications.‬
‭●‬ ‭Node.js‬‭– Uses JavaScript for backend development.‬
yS
‭2. PHP Development‬
‭ HP (Hypertext Preprocessor) is a popular open-source server-side scripting language used‬
P
‭for developing dynamic websites and applications.‬
da

‭2.1 PHP Scripts‬

‭ HP scripts are enclosed within‬‭


P <?php ... ?>‬‭tags‬‭and are executed on the server before‬
‭the output is sent to the browser.‬
ne

‭2.2 Basic PHP Syntax‬

<?php‬‭and end with‬‭


‭●‬ ‭PHP scripts start with‬‭ ?>‬
‭.‬
;‬
‭●‬ ‭Statements are terminated with a semicolon‬‭‭.‬
‭O

$‭.‬‬
‭●‬ ‭Variables begin with‬‭
// Single-line‬‭and‬‭
‭●‬ ‭Comments:‬‭ /* Multi-line */‬
‭.‬

‭Example:‬

‭<?php‬
‭echo "Hello, World!";‬
‭?>‬

‭2.3 PHP Variables‬


‭OnedayStudy WebTech‬‭Visit‬

$‭,‬followed by a name.‬
‭Variables store data and start with‬‭

‭ name = "John";‬
$
‭$age = 25;‬

‭‬ V
● ‭ ariables are case-sensitive.‬
‭●‬ ‭They do not require explicit declaration.‬
‭●‬ ‭Supported data types include strings, integers, floats, arrays, objects, etc.‬

‭2.4 PHP Data Types‬


‭●‬ ‭String‬‭: A sequence of characters (‬‭
"Hello"‬
‭)‬

dy
‭●‬ ‭Integer‬‭: Whole numbers (‬‭
123‬
‭)‬
‭●‬ ‭Float‬‭: Decimal numbers (‬‭
3.14‬
‭)‬
true‬‭or‬‭
‭●‬ ‭Boolean‬‭:‬‭ false‬
‭‬ A
● ‭ rray‬‭: Collection of values (‬‭
$colors = array("Red",‬‭
"Green");‬
‭)‬

tu
‭●‬ ‭Object‬‭: Instance of a class‬

‭2.5 Displaying Type Information‬


yS
‭●‬ ‭
gettype(variable)‬
‭: Returns the data type.‬
‭●‬ ‭
var_dump(variable)‬
‭: Displays type and value.‬

‭Example:‬
da

‭ var = 10.5;‬
$
‭echo gettype($var); // Output: double‬
‭var_dump($var); // Output: float(10.5)‬
ne

‭2.6 Testing for a Specific Data Type‬

‭PHP provides functions to check data types:‬

‭●‬ ‭
is_int($var)‬
‭: Checks if it is an integer.‬
‭O

‭●‬ ‭
is_string($var)‬
‭: Checks if it is a string.‬
‭●‬ ‭
is_array($var)‬
‭: Checks if it is an array.‬

‭Example:‬

‭ var = "Hello";‬
$
‭if (is_string($var)) {‬
‭echo "Variable is a string.";‬
‭}‬
‭OnedayStudy WebTech‬‭Visit‬

‭3. JSP & Servlets‬


‭ SP (JavaServer Pages) and Servlets are Java-based technologies used for web‬
J
‭development.‬

‭3.1 Basics of JSP‬

‭JSP is a server-side technology that allows embedding Java code in HTML.‬

‭Example of a simple JSP file:‬

‭ %@ page language="java" contentType="text/html; charset=UTF-8" %>‬


<


‭<html>‬

dy
‭<body>‬
‭<h1>Hello, JSP!</h1>‬
‭</body>‬
‭</html>‬

‭3.2 JSP Tags‬


tu
yS
<%@ %>‬‭(e.g., importing classes)‬
‭●‬ ‭Directive Tags‬‭:‬‭
<%! %>‬‭(Declaring variables)‬
‭●‬ ‭Declaration Tags‬‭:‬‭
<% %>‬‭(Adding Java code inside JSP)‬
‭●‬ ‭Scriptlet Tags‬‭:‬‭
<%= %>‬‭(Printing values)‬
‭●‬ ‭Expression Tags‬‭:‬‭
da

‭Example:‬

‭<%!‬
‭int num = 10;‬
‭%>‬
ne

‭<%‬
‭num += 5;‬
‭%>‬
‭The value is: <%= num %>‬
‭O

‭3.3 Session Handling in JSP‬

‭Sessions track user data across pages.‬

‭ %‬
<
‭session.setAttribute("username", "John");‬
‭%>‬
‭Welcome, <%= session.getAttribute("username") %>!‬
‭OnedayStudy WebTech‬‭Visit‬

‭3.4 Redirection in JSP‬

‭Redirects users to another page.‬

‭ %‬
<
‭response.sendRedirect("home.jsp");‬
‭%>‬

‭4. Basics of Servlets‬


‭Servlets are Java programs that run on a web server and handle HTTP requests.‬

dy
‭4.1 Servlet Lifecycle‬

‭1.‬ ‭Initialization‬‭(‭
i
‬ nit()‬
‭) – Called once when servlet‬‭is loaded.‬
‭2.‬ ‭Request Handling‬‭(‬‭
service()‬
‭) – Processes client requests.‬

tu
‭3.‬ ‭Destruction‬‭(‭
d
‬ estroy()‬
‭) – Cleans up resources before‬‭termination.‬

‭4.2 Writing a Simple Servlet‬


yS
i‭mport java.io.*;‬
‭import javax.servlet.*;‬
‭import javax.servlet.http.*;‬

‭public class HelloServlet extends HttpServlet {‬


da

‭protected void doGet(HttpServletRequest request, HttpServletResponse response) throws‬


‭ServletException, IOException {‬
‭response.setContentType("text/html");‬
‭PrintWriter out = response.getWriter();‬
‭out.println("<h1>Hello, Servlet!</h1>");‬
ne

‭}‬
‭}‬

‭4.3 Deploying a Servlet‬


‭O

‭ .‬ C
1 javac HelloServlet.java‬
‭ ompile the servlet:‬‭
‭2.‬ ‭Deploy it in a web server (e.g., Apache Tomcat).‬
‭3.‬ ‭Configure‬‭web.xml‬‭for mapping.‬

web.xml‬
‭Example‬‭ ‭:‬

‭<servlet>‬
‭<servlet-name>HelloServlet</servlet-name>‬
‭<servlet-class>HelloServlet</servlet-class>‬
‭</servlet>‬
‭OnedayStudy WebTech‬‭Visit‬

‭<servlet-mapping>‬
‭<servlet-name>HelloServlet</servlet-name>‬
‭<url-pattern>/hello</url-pattern>‬
‭</servlet-mapping>‬

‭4.4 Handling Sessions in Servlets‬

‭To maintain user session:‬

‭ ttpSession session = request.getSession();‬


H
‭session.setAttribute("username", "John");‬


‭out.println("Welcome, " + session.getAttribute("username"));‬

dy
‭4.5 Redirecting in Servlets‬

‭Redirecting to another page:‬

‭response.sendRedirect("home.jsp");‬

tu
yS
‭Conclusion‬
‭‬ P
● ‭ HP‬‭is widely used for server-side development due‬‭to its simplicity.‬
‭●‬ ‭JSP & Servlets‬‭provide Java-based solutions for dynamic‬‭web applications.‬
da

‭●‬ ‭Session handling and redirection‬‭are key concepts‬‭in web applications.‬

‭ his unit provides a foundation for building dynamic, interactive, and secure web‬
T
‭applications using PHP and Java-based technologies.‬
ne

‭Other Subject Resources:-‬


‭O

‭ SP.NET—>‬ ‭OPEN‬
A
‭SOFTWARE ENGINEERING —>‬‭OPEN‬
‭OBJECT ORIENTED PROGRAMMING USING JAVA —->‬‭OPEN‬
‭ONEDAYSTUDY —->‬‭OPEN‬

You might also like