Lpt-lab2

  • Uploaded by: sankarthamma
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Lpt-lab2 as PDF for free.

More details

  • Words: 656
  • Pages: 3
Faculty of ESBE

Internet Protocols & Technologies

Lab 2: JSP Web Applications The aim of this lab session is to develop simple JSP web applications that run on Tomcat web server.

Equipments: Two networked PCs with Red Hat Linux operating systems, logbook, and a USB memory stick for saving your work.

Exercises 1: 1. Create a JSP file called date1.jsp, and save it in the /opt/tomcat/webapps/test directory. Date 1 <% // This is a scriptlet. Notice that the "date" // variable we declare here is available in the // embedded expression later on. System.out.println( "Evaluating date now" ); java.util.Date date = new java.util.Date(); %> Hello! The time is now <%= date %>

2. From the second computer, go to graphical desktop, open a web browser, and type in following URL: http://xxx.xxx.xxx.xxx:8080/test/date1.jsp , where xxx.xxx.xxx.xxx is the first computer’s IP address or domain name. Comment the results. 3. Create another JSP file called date2.jsp, and save it in the /opt/tomcat/webapps/test directory. <%@ page import=”java.util.*” %> <%@ page import=”java.text.*” %> Date 2 <% Date date = new Date(); String today=DateFormat.getDateInstance().format(date); %> Today is: <em> <%= today %>

4. From the second computer, go to graphical desktop, open a web browser, and type in following URL: http://xxx.xxx.xxx.xxx:8080/test/date2.jsp , where xxx.xxx.xxx.xxx is the first computer’s IP address or domain name. Comment the results.

Dr. Perry XIAO

Copyright © 2000-2009, London South Bank University

1

Faculty of ESBE

Internet Protocols & Technologies

5. Create another JSP file called random.jsp, and save it in the /opt/tomcat/webapps/test directory. <%@ page language=”java” %> <%@ page import=”java.util.Random” %> Random Number <%! Random rand = new Random(); %> <%! public double getRandomNumber(){ return (rand.nextDouble()*1000); } %>

Here is a random number: <%=getRandomNumber() %>

And another: <%=getRandomNumber() %>

and one more: <%=getRandomNumber() %>



6. From the second computer, go to graphical desktop, open a web browser, and type in following URL: http://xxx.xxx.xxx.xxx:8080/test/random.jsp , where xxx.xxx.xxx.xxx is the first computer’s IP address or domain name. Comment the results. 7. Base on the above example, create a JSP web application called lottery.jsp, that can give six lottery numbers each time when you load the page, it should also show the date and time.

Exercises 2: 1. Create a HTML file called Login1.html, and save it in the /opt/tomcat/webapps/test directory. Login Page
Login name:
Password :



2. Create a JSP file called Login1.jsp, and save it in the /opt/tomcat/webapps/test directory. JSP Login Page

Dr. Perry XIAO

Copyright © 2000-2009, London South Bank University

2

Faculty of ESBE

Internet Protocols & Technologies

<% String uname = request.getParameter("j_username"); String upass = request.getParameter("j_password"); %> <%! public String login(String uname, String upass){ String t=""; if (uname.compareTo("xiaop")==0 && upass.compareTo("letmein")==0){ t="Successful!"; } else{ t="Failed!"; } return t; } %>

Login <%= login(uname, upass) %>



3. From the second computer, go to graphical desktop, open a web browser, and type in following URL: http://xxx.xxx.xxx.xxx:8080/test/Login1.html, where xxx.xxx.xxx.xxx is the first computer’s IP address or domain name. Comment the results. 4. Modify the above two programs, so if login is successful it will display a welcome message and the system time (welcome.jsp), and if failed it will display an error message (error.html). Hint: use pageContext.forward(“welcome.jsp”) or pageContext.forward(“error.html”) within the if else structure.

References: 1. 2. 3. 4. 5. 6. 7. 8.

http://java.sun.com http://tomcat.apache.org/ http://www.linux-sxs.org/internet_serving/ http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html http://www.jsptut.com/ http://eent3.sbu.ac.uk/staff/xiaop David Harms, “JSP, Servlets, and MySQL”, ISBN: 0764547879, M&T Book, 2001 (http://www.covecomm.com/java). 9. Barry Burd, JSP: JavaServer Pages, ISBN:0764535358, M & T Books, 2001

Questions: 1. 2. 3. 4.

What are the main differences between JSP and Servlet? What is the Container in the context of JSP/Servlet technologies? How to declare variables in JSP? How to pass information between a HTML file and a JSP file?

Dr. Perry XIAO

Copyright © 2000-2009, London South Bank University

3

More Documents from "sankarthamma"

Lpt-lab2
April 2020 15