HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Dynamic Page Compilation with the Java Web Server"
Vol. 3, Issue 6, P.46

	

Listing 1.

<java type=import>
java.io.*
javax.servlet.*
javax.servlet.http.*
</java>

Listing 2.

<java type=import>
java.io.*
javax.servlet.*
javax.servlet.http.*
</java>

<html>
<head>
<title>Java Loop</title>
</head>
<body>

<table>
<java> for (int I = 0; I < 5; I++) { </java>
	<tr>
		<td>
			<java type=print> ²<b>² + I + ³</b>² </java>
		</td>
	</tr>
<java> } </java>
</table>

</body>
</html>

Listing 3.

<java type=import>
java.io.*
javax.servlet.*
javax.servlet.http.*
</java>

<html>
<head>
<title>Java Cookies</title>
</head>
<body>

<java>
//sending cookies
Cookie outCookie = new Cookie(³Name², ³Value²);
outCookie.setMaxAge(2 * 24 * 60 * 60);
response.addCookie(outCookie);

//receiving cookies
Cookie inCookie[] = request.getCookies();
for (int I = 0; I < inCookie.length; I++) {
	out.print(inCookie[I].getName());
	out.print(inCookie[I].getValue());
}
</java>

</body>
</html>

Listing 4.

<java>
session.putValue("Item", "Shirt");  //adds an Item called Shirt
session.getValue("Item") //gets the Item and returns Shirt
session.invalidate //kills this session
if (session.isNew()) {	//checks to see if you're new 
	...do this...;
}
</java>

Listing 5.

<java>
String x = request.getParameter(³Name²);
out.print(x);
</java>

Listing 6.

<java type=import>
java.io.*
java.net.*
</java>

<java>request.sendRedirect("index.html")</java>

Listing 7.

<java type=import>
java.io.*
java.net.*
</java><java>request.sendRedirect("index.html")</java>
	

Listing 8.

<java type=import>
smtp.SendMail
</java>

<html>
<head>
<title>Send some mail</title>
</head>
<body>

<java>
SendMail x = new SendMail();
x.smtpHost = "mx2.insource.com";
x.smtpFrom = "[email protected];
x.smtpToEmail = "[email protected];
x.smtpToName = "Brian Towles";
x.smtpSubject = "The Java Web Server can send email";
x.smtpMessage = "Hello World";
String result = x.Send();
out.print(result);
</java>

</body>
</html>

Listing 9.

<java type=import>
java.sql.*
</java>
		
<html>
<head>
<title>dbselect</title>
</head>
<body>

<java>
try {
	//load oracle driver
	DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
	//connect to database
Connection cn = DriverManager.getConnection(³jdbc:oracle:thin:@host:1521:orcl², ³scott², ³tiger²);

	//query
	Statement st = cn.createStatement();
	ResultSet rs = st.executeQuery(³select ename from emp²);
</java>

<table>
<java> while (rs.next()) { </java>
	<tr>
		<td>
			<java type=print>rs.getString(1)</java>
		</td>
	</tr>
<java> } </java>
</table>
<java>
rs.close();
st.close();
cn.close();
} catch(Exception e){	out.print(e.getMessage());}
</java>
</body>
</html>
  
      
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.