1 / 22

Introduction To HTML

Introduction To HTML. Dr. Magdi AMER. HTML elements. Tables. Links. <a href =‘www.ite.com’> click here </a>. Forms. Forms. Web Architecture. HTTP Get Request. An HTTP request has three parts, separated by spaces: A method name The local path of the requested resource (URI)

irisa
Download Presentation

Introduction To HTML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction To HTML Dr. Magdi AMER

  2. HTML elements

  3. Tables

  4. Links <a href=‘www.ite.com’> click here </a>

  5. Forms

  6. Forms

  7. Web Architecture

  8. HTTP Get Request • An HTTP request has three parts, separated by spaces: • A method name • The local path of the requested resource (URI) • The version of HTTP being used GET /reports/sales/index.html HTTP/1.1 • If parameters are required, they are passed by appending a query string to the URI name1=value1&name2=value2&…&nameM=valueM

  9. HTTP Post Request • In POST, the parameters are sent in the message body, unlike in GET, in which they are a part of the request URI. • Post result cannot be bookmarked, while get result can be bookmarked.

  10. First Servlet package com.amer; import java.io.*; import javax.servlet.*; import javax.servlet.http.*;  public class HelloWorld extends HttpServlet {  public void doPost(HttpServletRequestreq, HttpServletResponse res) throws ServletException, IOException { doGet(req, res);} public void doGet(HttpServletRequestreq, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter();  out.println("<HTML>"); out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>"); out.println("<BODY>"); out.println("<BIG>Hello World</BIG>"); out.println("</BODY></HTML>"); }}

  11. Calling a Servlet • As a link:  always GET <a href=‘/appName/HelloWorld?var1=value&var2=value2’> go</a> • As a form action  can choose GETor POST <form method=‘GET’ action=‘/appName/HelloWorld’> ….</form>

  12. Reading Parameters //Single parameter String uname= request.getParameter("uname"); String gender = request.getParameter(“gender”); If(gender == null) gender=“”; //Multi parameters String[] langs = request.getParameterValues("lang"); if(langs==null) langs = new String[0];

  13. Parameters Types Input type: text, password, hidden, single combo, text area  single, never null • Input type: radio, submit •  single, may be null • Input type: checkbox, multi combo •  multi, may be null

  14. web.xml • <?xml version = '1.0' encoding = 'UTF-8'?> • <servlet> • <servlet-name>HelloWorld</servlet-name> • <servlet-class>eg.edu.ufe.tic4.HelloWorld</servlet-class> • </servlet> • <servlet-mapping> • <servlet-name>HelloWorld</servlet-name> • <url-pattern>/hi</url-pattern> • </servlet-mapping> • <servlet-mapping> • <servlet-name>HelloWorld</servlet-name> • <url-pattern>*.php</url-pattern> • </servlet-mapping> • </web-app>

  15. History of the web

  16. Handling Multi-threads

  17. Handling Multi-treading 1- do not use instence variables or shared objects in servlets 2- If really necessary use synchronized synchronized(this) { int y= x; // x is an instance variable, shared between multiple threads // y is a function variable, unique for each thread y = y+100; x = y; }

  18. JSP <%@ page contentType="text/html;charset=UTF-8" import="com.amer.*”%> <%@ page import=“java.util.*" %> <select name=‘gov’> <% //java code out.println(“<BR/>NAME”); %> </select> <%=variable%>  <%out.print(variable);%> <%! //variable and function declaration %> <BR>

  19. JSP to Servlet import com.amer.*; public class JspToServlet extends HttpServlet { //variable and function declaration public void doPost(HttpServletRequestreq, HttpServletResponse res) throws ServletException, IOException { doGet(req, res);} public void doGet(HttpServletRequestreq, HttpServletResponse res) throws ServletException, IOException {  PrintWriter out = res.getWriter(); res.setContentType("text/html"); res.setCharacterEncoding(“UTF-8”); //java code out,print(“<BR/>NAME”): out.print(variable); out.println(“<BR>”); }

  20. Dispatching request from Servlet to JSP RequestDispatcher dispatcher = this.getServletContext(). getRequestDispatcher("/Login.jsp"); dispatcher.forward(request, response);

  21. Passing data from Servlet to JSP //Servlet 1 Vector<Employee> list = null; //………… request.setAttribute(“list”, list); //JSP <% Vector<Employee> list = (Vector<Employee>) request.getAttribute(“list”); %>

  22. Sessions //to create a session HttpSession session = req.getSession(true); User u = new User(); //any object // to store a value in the session session.setAttribute(“user”, u); //////////////////////////////////// //To obtain an instance of an existing session HttpSession session = req.getSession(); // to read a value User u = (User) session.getAttribute(“user”);

More Related