Appendix E
Java Basics

E.1 Java SE Basics

Section waiting for contribution (2’000-3’000 words) The goal of this section is to provide the reader with a solid overview of the non-trivial Java concepts relevant for scout applications and central aspects of the framework itself. The focus of this section is on the Java Standard Edition (Java SE). Where appropriate, provide links to high quality online material, that is likely to exist for at least the next year or two.

E.1.1 Learning Java

To progam Scout applications you need to have a solid understanding of the Java language. Scout will only work for you if you have achieved a certain proficiency level in Java.

Luckily, free online tutorials to learn Java are offered in many places. A good starting point is the official Java documentation site1 . If you prefer to work with video tutorials we recommend “Eclipse and Java for Total Beginners”2 , although the installation used is somewhat out of date. As for printed books, we suggest to start with either “Head First Java”[1] or “Thinking in Java”[3]. Highly recommended but slightly more advanced is “Effective Java”[2].

To solve really tricky Java problems there is often no way around the Java specification3 itself. Just make sure to pick the right Java version for your context.

E.1.2 Advanced Java SE Concepts

* say which non-trivial things are vital to good understanding * threading * generics * annotations

E.1.3 JAR Files

* purpose * directory structure * example

E.2 Java EE Basics

Section waiting for contribution (2’000-5’000 words) The goal of this section is to provide the reader with a solid overview of the non-trivial Java enterprise concepts relevant for scout applications and central aspects of the framework itself. The focus of this section is on the Java Enterprise Edition (Java EE) Where appropriate, provide links to high quality online material, that is likely to exist for at least the next year or two.

needs text

* maybe the same as for java foundation, maybe not * jaas * http comm * servlet * servlet filters

E.2.1 Servlets

A very comprehensive and detailed step to step description has been written by Chua Hock-Chuan4 .

may be found online do servlet stuff with annotations (JEE6) not JEE5?


Listing E.1: The index.html start page for the tiny servlet application.
 
<html> 
<head> 
<title>tiny servlet title</title> 
</head> 
<body style=color:green> 
<!-- link must correspond to url-pattern in servlet-mapping of web.xml --> 
go to <a href=servlets/Tiny>tiny servlet</a> 
</body> 
</html>


Listing E.2: The web.xml file of the tiny servlet application.
 
<?xml version=”1.0” encoding=”UTF-8” ?> 
<!DOCTYPE web-app PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.3//EN http://java.sun.com/dtd/web-app_2_3.dtd> 
 
<web-app> 
 <display-name>tiny servlet app</display-name> 
 
 <!-- declaration of servlet for this app --> 
 <servlet> 
   <!-- unique servlet symbolic name --> 
   <servlet-name>Tiny</servlet-name> 
      <!-- full path to class (relative from WEB-INF/classes) --> 
   <servlet-class>TinyServlet</servlet-class> 
 </servlet> 
 
 <!-- mapping of url to servlet defined above --> 
 <servlet-mapping> 
   <servlet-name>Tiny</servlet-name> 
   <url-pattern>/servlets/Tiny</url-pattern> 
 </servlet-mapping> 
</web-app>


Listing E.3: The complete TinyServlet source code.
 
// servlet browser link http://localhost:8080/tinyservlet/ 
// direct link to servlet: http://localhost:8080/tinyservlet/servlets/Tiny 
 
// tomcat overview: http://localhost:8080/ 
// application admin: http://localhost:8080/manager/html/list 
 
// compiling 
// servlet jar has to be found in WEB-INF/lib/ (to be found in apache servlet container, as well for compiling above) 
// mzi@bsim013 ~/Desktop/jee/servlet1/WEB-INF/sources 
// (0) cd /cygdrive/C/Documents\ and\ Settings/mzi/Desktop/jee/tinyservlet/WEB-INF/sources 
// (1) /cygdrive/C/java/jdk1.5.0_16/bin/javac -classpath ”../lib/javax.servlet_2.4.0.v200806031604.jar;.” TinyServlet.java 
// (2) mv TinyServlet.class ../classes 
 
// deploying 
// servlet jar has to be found in WEB-INF/lib/ (to be found in apache servlet container, as well for compiling above) 
// (1a) zip contents of C:\Documents and Settings\mzi\Desktop\jee\tinyservlet 
// (1b) rename to tinyservlet.zip to tinyservlet.war 
// (2) copy war to C:\tomcat\tomcat70\webapps 
// (3) restart tomcat (or remove folder tinyservlet from webapps and restart with war file only) 
 
import java.util.Date; 
import java.io.IOException; 
 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.ServletException; 
 
public class TinyServlet 
 extends HttpServlet 
{ 
 public void service(HttpServletRequest request, HttpServletResponse response) 
   throws IOException, ServletException 
 { 
   response.setContentType(text/html;charset=ISO-8859-1); 
      response.getWriter().println( 
       <html>+ 
       <head><title>tiny servlet</title></head>+ 
       <body style=\text-align:center\> + 
       TinyServlets server time:  + new Date() + 
       </body> + 
       </html> 
      ); 
 } 
}

DONT include servlet jar inside of war file (tomcat doesn’t like it)

E.2.2 Servlet Filters

hello world example (JEE6)

E.2.3 WAR Files

war file organisation: http://documentation.progress.com/output/Iona/orbix/6.1/tutorials/fnb/dev_intro/j2ee_overview8.html