Professional Documents
Culture Documents
Intro To J Sps and Serv Lets
Intro To J Sps and Serv Lets
Xabriel J. Collazo Mojica TA for ICOM 5016 University of Puerto Rico at Mayagez
Agenda
Theory
MVC Pattern JSPs & Servlets dened Things you need to know Project Hierarchy
Practice
Java on a JSP Scriplets, EL & Standard Actions Your projects rst phase Quick workshop
Saturday, October 11, 2008
From [2]
Saturday, October 11, 2008
From [1]
Saturday, October 11, 2008
Suns definitions
Servlets are Java programming language classes
execute as servlets but allow a more natural approach to creating static content.
From [1]
Saturday, October 11, 2008
Servlet API & JSP API Used to make all the nifty dynamic tricks. SQL : Structured Query Language
The core of your project.
Sun
For example, if it is the Servlet API we want to add, we click on Add External JARs and browse to the jar le.
Note that in the case of Tomcat, the jar we want is at: /tomcat_root/ common/lib/servletapi.jar
Java on a JSP
You can add Java to a JSP in three different ways:
As a Directive <%@ page import=foo.* %> As a Scriplet
<% out.println(foo.javaGoesHere())
; %>
10
11
<%if(request.getParameter("mainTable") == null){ %> <jsp:include page="include/indexMainTableRoundTrip.jsp" /> <%} else if(request.getParameter("mainTable").equalsIgnoreCase("OneWay")){ %> <jsp:include page="include/indexMainTableOneWay.jsp" /> <%} else if(request.getParameter("mainTable").equalsIgnoreCase("MultiWay")){ %> <jsp:include page="include/indexMainTableMultiWay.jsp" /> <%} else{ %> <jsp:include page="include/indexMainTableRoundTrip.jsp" /> <%} %>
12
13
no better denition!)
Example:
14
JSTL
JSTL : Everyday stuff (like loops & conditionals)
Example:
<table> <c:forEach var="person" items="${people.people}"> <tr> <td>${person.name}</td> <td>${person.age}</td> <td>${person.height}</td> </tr> </c:forEach> </table>
Saturday, October 11, 2008
15
16
17
anything.
But be advised!
I recommend you use EL, JSTL and/or Standard
18
Anyway
Nothing of this applies to the rst phase of your
19
20
21
WhatYouNeedToDoForFirstPhase Workshop
Heres where you actually do some work
22
javaee/5/docs/tutorial/doc/index.html.
betterexplained.com/articles/intermediate-railsunderstanding-models-views-and-controllers/
Book: Head First Servlets & JSP. OReilly. Some year :) All other links direct to the Wikipedia articles on the
respective subjects.
23