Java Servlets and JSP: Accessible, Efficient, and Powerful Web Technologies - Prof. Benjam, Study notes of Computer Science

An overview of java servlets and jsp (java server pages), two powerful and efficient technologies for building dynamic web applications. The author compares jsp and servlets, as well as jsp and asp, and discusses the advantages of java servlets, such as accessibility, avoiding html code duplication, and multi-lingual support. The document also covers open source tools like tomcat, eclipse, and mysql, and provides examples of jsp and servlet code.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-xks
koofers-user-xks 🇺🇸

10 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Java Servlets and
Java Server Pages (JSP)
Hilary Hutchinson
HCIL Staff/PhD Student
May 10, 2005
Motivation
Accessibility
Not everyone has .NET
Not everyone runs Windows
Avoid duplication in HTML code
Many web apps have lots of content that
can all be presented via same template
More efficient and powerful than CGI
Java VM threads vs. OS processes
Store session info, talk to web server
Portable to many platforms
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Java Servlets and JSP: Accessible, Efficient, and Powerful Web Technologies - Prof. Benjam and more Study notes Computer Science in PDF only on Docsity!

Java Servlets and

Java Server Pages (JSP)

Hilary Hutchinson

HCIL Staff/PhD Student

[email protected]

May 10, 2005

Motivation

„ Accessibility

  • Not everyone has .NET
  • Not everyone runs Windows

„ Avoid duplication in HTML code

  • Many web apps have lots of content that

can all be presented via same template

„ More efficient and powerful than CGI

  • Java VM threads vs. OS processes
  • Store session info, talk to web server
  • Portable to many platforms

JSP vs. ASP

„ Embed logic in an HTML page and

parse it on the server-side

„ ASP (Active Server Pages)

  • Platform dependent (Microsoft)
  • Uses scripting (VBScript or Jscript)

„ JSP (Java Server Pages)

  • Platform independent
  • Uses a real programming language (Java)

JSP vs. Servlets

„ 2 ways to do the same thing

„ Regular Java programming

„ Access HTTP request/response info

„ JSP

  • Java code is embedded in HTML page
  • Page gets compiled into a servlet by server

„ Servlets

  • Plain old Java classes
  • Extend javax.servlet.http.HttpServlet

Open Source Tools

„ Server: Tomcat

„ Development Environment: Eclipse

„ Database: mySQL

„ Database Connectivity: JDBC

„ Build tool: Ant

„ Text Search: Lucene

Servers

„ Tomcat

  • Free from Apache: http://jakarta.apache.org/tomcat
  • Run alone or integrate into Apache
  • Easy to install on Windows or UNIX: http://www.coreservlets.com/Apache-Tomcat-Tutorial

„ Others ($$)

  • IBM WebSphere
  • Allaire JRun
  • Oracle Application Server

Tomcat Examples

„ JSP

  • http://localhost:8080/HelloWorld.jsp

„ Servlet

  • http://localhost:8080/servlet/HelloWorld

Real Example: ICDL

„ Online library of scanned children’s books

  • 10,000 books
  • 100 languages

„ Technical needs

  • Client-side accessibility
  • Templates to handle duplication
  • Multi-lingual support
  • Cheap or free

Per Page: Url Variables

„ Quick and dirty – like HTML forms

„ Client side:

www.icdlbooks.org/icdl/BookPreview ?id=

„ Server side:

public void doGet (HttpServletRequest request, HttpServletResponse response) {

String id= request.getParameter ("id");

}

Per User: Session Variables

„ Remembering state about a user

„ Setting: public void doGet (HttpServletRequest request, HttpServletResponse response) { HttpSession ses= request.getSession (true); Profile profile=new Profile(“Hilary”) ses. setAttribute ("profile",profile); ses. setMaxInactiveInterval (1000); }

„ Getting: HttpSession ses= request.getSession (true); Profile profile= ses.getAttribute (“profile”)

Per Servlet: Context Variables

„ Remembering state that all users need

„ Setting:

public class ContextListener implements ServletContextListener { public void contextInitialized ( ServletContextEvent event) { context = event. getServletContext (); String home=“www.icdlbooks.org”; context. setAttribute (“home”,var); } public void contextDestroyed (ServletContextEvent event) { context. removeAttribute (“home"); }

Per Servlet: Context Variables

„ Getting:

public class MyServlet extends HttpServlet{

public void doGet(…) { ServletConfig config= getServletConfig(); ServletContext context= config.getServletContext(); String home= (String) context.getAttribute (“home");

}