Assignment 6 - Software Technology Group

tastelessbeachInternet and Web Development

Nov 12, 2013 (4 years ago)

75 views

http://www.st.informatik.tu-darmstadt.de/
Assignment
6
©
2003 Software Technology Group -
Prof. Dr. Klaus Ostermann
Departmen
t of Computer Science
Darmstadt University of Technology
Dipl. Inform. Sven Kloppenburg
Di
pl. Inform
I
vica Arac
ic
http://www.st.informatik.tu-darmstadt.de/
2
Topics

Lecture Summary

Ania
Augustyn
+ Monica Manrique

Result Presentation

Sebastian Rose + Donnaruma
G
ennaro

Announcement: Seam Talk

Assignment Presentation

State management in web applications
http://www.st.informatik.tu-darmstadt.de/
Seam
Talk
©
2003 Software Technology Group -
Prof. Dr. Klaus Ostermann
Departmen
t of Computer Science
Darmstadt University of Technology
Dipl. Inform. Sven Kloppenburg
Di
pl. Inform
I
vica Arac
ic
http://www.st.informatik.tu-darmstadt.de/
4
Seam -
Talk (Christian Bauer jBoss)
JBoss
Seam:
Contextual
Components
simplify
Web
application
development
8.6.2006, 14:00, S101|054
http://www.st.informatik.tu-darmstadt.de/
5
Seam Features

Integrates JSF (presentation) with
EJB3 (persistence)

Declarative State Management

Annotated POJOs
(Plain Old Java Objects)

http://www.jboss.com/products/seam
http://www.st.informatik.tu-darmstadt.de/
Assignment
State Management in
Web-Applications
©
2003 Software Technology Group -
Prof. Dr. Klaus Ostermann
Departmen
t of Computer Science
Darmstadt University of Technology
Dipl. Inform. Sven Kloppenburg
Di
pl. Inform
I
vica Arac
ic
http://www.st.informatik.tu-darmstadt.de/
7
Introducing Servlets
and JSPs
public class SomeServlet
extends HttpServlet
{
public void doGet(
HttpServletRequest
request,
HttpServletResponse
response
) throws ServletException, IOException
{
String name = request.getParameter("name");
PrintWriter
out = response.getWriter();
out.println("<html><body><b>Name:</b>");
out.println(name);
out.println("</body></html>");
}
}
http://www.st.informatik.tu-darmstadt.de/
8
Java Server Pages (JSPs)
<%
String name = request.getAttribute("name");
%>
<html>
<body>
<b>Name:</b> <%=name%>
</body>
</html>
http://www.st.informatik.tu-darmstadt.de/
9
JSPs: Predefined Variables

request

request.getParameter(String)

out

out.println(String);

session

session.getAttribute(String)

session.setAttribute(String, Object)

see full list at
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
doSomething.jsp?name=Ivica
reques
t.getParameter("name")
http://www.st.informatik.tu-darmstadt.de/
10
JSPs: Syntax Overview
<%@page import="java.util.List, java.util.Map"%>
<%!
String someFunction(String
str) {
....
}
%>
<%
String name = request.getAttribute("name");
%>
<html>
<body>
<b>Name:</b> <%=someFunction(name)%>
</body>
</html>
page directive
declaration block
service method code block
expression block
<% out.print(name); %>
http://www.st.informatik.tu-darmstadt.de/
11
Mixing of JSP Code Fragments and HTML
<%
if (Math.random() < 0.5) {%>
Have a <B>nice</B> day!
<%} else {%>
Have a <B>lousy</B> day!
<%}%>
is equivalent to:
<%
if (Math.random() < 0.5) {
out.println("Have
a <B>nice</B> day!");
} else {
out.println("Have
a <B>lousy</B> day!");
}
%>
http://www.st.informatik.tu-darmstadt.de/
12
HTML Forms
<form action="/exercise6/some.jsp" method="get|post">
<input type="text" name="x" value="10"/>
<input type="hidden" name="y" value="11"/>
<input type="submit" name="go" value="GO!"/>
</form>
request.getParameter("x");
request.getParameter("y");
request.getParameter("go");
http://www.st.informatik.tu-darmstadt.de/
13
Configuring your Tomcat

Import the Project from eAssignment

Add a new context in conf/server.xml
<Host ....>
<Context path="/exercise6"
docBase="<path-to-the-project>/htdocs"
reloadable="true" />
...
</Host>

http://localhost:8080/exercise6/test.jsp
http://www.st.informatik.tu-darmstadt.de/
14
Your Assignment -
Part 1

A simple calculation machine

reads a sequence of numbers
(don't forget to validate the input)

multiplies or sums the input sequence
Result
Intro
Insert
Number
Choose Op
[ * | + ]
start
reset
add
calculate
calculate
http://www.st.informatik.tu-darmstadt.de/
15
Your Task -
part 1

Implement this application using JSPs

Variation 1:
The state is stored in a session on the server

Variation 2:
The state is stored on the client using hidden fields
http://www.st.informatik.tu-darmstadt.de/
16
Your Task -
part 2
Explain the behavior of your implementations for the
following scenarios:
Scenario 1:
Insert two numbers, hit back button, finish the calculation.
Scenario 2:
Insert two numbers, spawn a new window, start the wizard
again, add two numbers in the new wizard, return to the old
window and add a third number, finish the calculation.
Scenario 3:
Insert two numbers, spawn a new window, continue in the
new window where you've stopped, finish the calculation,
return to the old window, add a third number, finish the
calculation.
http://www.st.informatik.tu-darmstadt.de/
17
Your Task -
part 2
Your should describe the

observed behavior

expected behavior (what and why?)

potential problems for the user
Keep your explanation short (< 200 words / scenario)
http://www.st.informatik.tu-darmstadt.de/
18
Links

http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/

http://tomcat.apache.org/tomcat-5.0-doc/index.html

http://de.selfhtml.org/

http://de.selfhtml.org/html/index.htm

http://de.selfhtml.org/html/formulare/index.htm