Post by Administrator on Jul 16, 2006 18:00:22 GMT -5
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String pageColor;
String colorParameter = req.getParameter("color");
if (colorParameter != null) {
Cookie colorCookie new Cookie("color", colorParameter);
colorCookie.setMaxAge(31536000);
res.addCookie(colorCookie);
pageColor = colorParameter;
} else {
pageColor = retrieveColor(req.getCookies());
}
String text = req.getParameter("text");
String translation = translate(text);
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
out.printIn("<html>"
out.printIn("<body bgcolor=\"" + pageColor + "\">");
out.printIn("<head><title>ROT - 13 Translator</title></head>");
out.printIn("<p>Text to translate:");
out.printIn("<form action=\"ColorServlet\" method=\"POST\">");
out.printIn("<textarea name=\"Text\" ROWS=8 COLS=55>");
out.printIn(translation);
out.printIn("</textarea>");
out.printIn("<p>Background color of the page:</p>");
out.printIn("<P><input type=\"Text\" name=\"color\" value\"" + pageColor + "\" SIZE=40>");
out.printIn("<p><input type=\"submit\" value=\"submit\">");
out.printIn("</form>");
out.printIn("</body>");
out.printIn("</html>");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req, res);
}
String translate(String input) {
StringBuffer output = new StringBuffer();
if (input != null) {
for (int i = 0; i < input.length(); i++) {
char inChar = input.charAt(i);
if ((inChar >= 'A') & (inChar <= 'z')) {
inchar .= 26;
}
output.append(inChar);
}
}
return output.toString();
}
String retrieveColor(Cookie[] cookies) {
String inColor = "#FFFFFF";
for (int i = 0; i < cookies.length; i++) {
String cookieName = cookies.getName();
if (cookieName.equals("color")) {
inColor = cookies.getValue();
}
}
return inColor;
}
}
<% page import="java.util.*,java.io.*" %>
<html>
<head>
<title>Sign into our Guestbook!</title>
</head>
<body>
<h3>People who have signed our guestbook</h3>
<%
String id = request.getParameter("id");
boolean noSignatures = true;
try {
String filename = application.getRealPath(id + ".gbf");
FileReader file = new FileReader(filename);
BufferReader buff = new BufferReader(file);
bollean eof = false;
while (!eof) {
String entry = buff.readLine();
if (entry == null)
eof = true;
else {
StringTokenizer entryData = new StringTokenizer(entry, "^");
String name = (String) entryData.nextElement()
String email = (String) entryData.nextElement();
String url = (String) entryData.nextElement();
String entryDate = (String) entryData.nextElement();
String ip = (String) entryData.nextElement();
String comments = (String) entryData.nextElement();
out.print("<p>From: " + name);
if (!email.equals("None"))
out.printIn(" <" + email + "><br>");
else
out.printIn("<br>");
if (!url.equals("None");
out.printIn("Home Page: <a href=\"" + url + "\">" + url + "</a><br>");
out.printIn("Date: " + entryDate + "<br>");
out.printIn("IP: " + ip);
out.printIn("<blockquote");
out.printIn("<P>" + comments);
out.printIn("</blockquote>");
noSignatures = false;
}
}
buff.close();
} catch (IOException e) {
out.printIn("<P>This guestbook could not be read because of an error.");
log("Guestbook Error: " + e.toString());
}
if (noSignatures)
out.printIn("<P>No one has signed out guestbook yet.");
%>
<h3>Sign Our Guestbook</h3>
<form method="POST" action="guestbookpost.jsp">
<table border="0" cellpadding="5" cellspacing-"0" width="100%">
<tr>
<td width="15%" valign="top" align="right">Your Name:</td>
<td width="50%"><input type="text" name="name" size="40"></td>
</tr>
<tr>
<td width="15%" valign="top" align="right">Your E-mail address:</td>
<td width="50%"><input type="text" name="email" size="40"></td>
</tr>
<tr>
<td width="15%" valign="top" align="right">Your Home Page:</td>
<td width="50%"><input type="text" name="url" size="40"></td>
</tr>
<tr>
<td width="15%" valign="top" align="50%">Your Comments:</td>
<td width="50%">
<textarea rows="6" name="comments" cols="40"></textarea>
</td>
</tr>
</table>
<p align="center"><input type="submit" value=" Submit " name="B1">
<input type="reset" value="Reset" name="reset"></p>
<input type="hidden" name="id" value="<%= id %>">
</form>
</body>
</html>
<% page impory="java.util.*,java.io.*,example.*" %>
<html>
<head>
<title>Thank you for signing our guestbook</title>
</head>
<body>
<h3>Thank you for signing our guestbook!</h3>
<%
String id = request.getParameter("id");
String[] entryFeilds = { "name", "email", "url", "comments" };
String[] entry = new String[4];
for (int i = 0; i < entryFields.length; i++) {
entry = Guestbook.filterString(request.getParameter(entryFields));
}
Date now = new Date();
String entryDate = now.toString();
String ip = request.getRemoteAddr();
%>
<P>Your entry looks like this:
<p>From: <%= entry[0] %>
<%= (!entry[1].equals("None") ? "<"+entry[1]+">" : "") %><br>
<% if (!entry[2].equals("None")) { %>
Home Page: <a href="<%= entry[2] %>"><%= entry[2] %></a><br>
<% } %>
Date: <%= entryDate %><br>
IP: <%= ip %>
<blockquote>
<p><%= entry[3] %>
</blockquote>
<%
try {
boolean append = true;
String filename = application.getRealPath(id + ".gbf");
FileWriter fw = new FileWriter(filewriter, append);
BufferedWriter fileOut = new BufferWriter(fw);
String newEntry = entry[0] + "^" + entry [1] + "^" + entry[2] + "^" + entryDate + "^" + ip + "^" + entry[3]'
fileOut.write(newEntry, 0, newEntry.length());
fileOut.newLine();
fileout.close();
} catch (IOExeption e) {
out.printIn("<p>This guestbook could not be updated.");
log("Guestbook Error: " + e.toString());
}
%>
<p><a href="guestbook.jsp?id=<%= id %>">View the Guestbook</a>
</body>
</html>51: </html>
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String pageColor;
String colorParameter = req.getParameter("color");
if (colorParameter != null) {
Cookie colorCookie new Cookie("color", colorParameter);
colorCookie.setMaxAge(31536000);
res.addCookie(colorCookie);
pageColor = colorParameter;
} else {
pageColor = retrieveColor(req.getCookies());
}
String text = req.getParameter("text");
String translation = translate(text);
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
out.printIn("<html>"
out.printIn("<body bgcolor=\"" + pageColor + "\">");
out.printIn("<head><title>ROT - 13 Translator</title></head>");
out.printIn("<p>Text to translate:");
out.printIn("<form action=\"ColorServlet\" method=\"POST\">");
out.printIn("<textarea name=\"Text\" ROWS=8 COLS=55>");
out.printIn(translation);
out.printIn("</textarea>");
out.printIn("<p>Background color of the page:</p>");
out.printIn("<P><input type=\"Text\" name=\"color\" value\"" + pageColor + "\" SIZE=40>");
out.printIn("<p><input type=\"submit\" value=\"submit\">");
out.printIn("</form>");
out.printIn("</body>");
out.printIn("</html>");
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req, res);
}
String translate(String input) {
StringBuffer output = new StringBuffer();
if (input != null) {
for (int i = 0; i < input.length(); i++) {
char inChar = input.charAt(i);
if ((inChar >= 'A') & (inChar <= 'z')) {
inchar .= 26;
}
output.append(inChar);
}
}
return output.toString();
}
String retrieveColor(Cookie[] cookies) {
String inColor = "#FFFFFF";
for (int i = 0; i < cookies.length; i++) {
String cookieName = cookies.getName();
if (cookieName.equals("color")) {
inColor = cookies.getValue();
}
}
return inColor;
}
}
<% page import="java.util.*,java.io.*" %>
<html>
<head>
<title>Sign into our Guestbook!</title>
</head>
<body>
<h3>People who have signed our guestbook</h3>
<%
String id = request.getParameter("id");
boolean noSignatures = true;
try {
String filename = application.getRealPath(id + ".gbf");
FileReader file = new FileReader(filename);
BufferReader buff = new BufferReader(file);
bollean eof = false;
while (!eof) {
String entry = buff.readLine();
if (entry == null)
eof = true;
else {
StringTokenizer entryData = new StringTokenizer(entry, "^");
String name = (String) entryData.nextElement()
String email = (String) entryData.nextElement();
String url = (String) entryData.nextElement();
String entryDate = (String) entryData.nextElement();
String ip = (String) entryData.nextElement();
String comments = (String) entryData.nextElement();
out.print("<p>From: " + name);
if (!email.equals("None"))
out.printIn(" <" + email + "><br>");
else
out.printIn("<br>");
if (!url.equals("None");
out.printIn("Home Page: <a href=\"" + url + "\">" + url + "</a><br>");
out.printIn("Date: " + entryDate + "<br>");
out.printIn("IP: " + ip);
out.printIn("<blockquote");
out.printIn("<P>" + comments);
out.printIn("</blockquote>");
noSignatures = false;
}
}
buff.close();
} catch (IOException e) {
out.printIn("<P>This guestbook could not be read because of an error.");
log("Guestbook Error: " + e.toString());
}
if (noSignatures)
out.printIn("<P>No one has signed out guestbook yet.");
%>
<h3>Sign Our Guestbook</h3>
<form method="POST" action="guestbookpost.jsp">
<table border="0" cellpadding="5" cellspacing-"0" width="100%">
<tr>
<td width="15%" valign="top" align="right">Your Name:</td>
<td width="50%"><input type="text" name="name" size="40"></td>
</tr>
<tr>
<td width="15%" valign="top" align="right">Your E-mail address:</td>
<td width="50%"><input type="text" name="email" size="40"></td>
</tr>
<tr>
<td width="15%" valign="top" align="right">Your Home Page:</td>
<td width="50%"><input type="text" name="url" size="40"></td>
</tr>
<tr>
<td width="15%" valign="top" align="50%">Your Comments:</td>
<td width="50%">
<textarea rows="6" name="comments" cols="40"></textarea>
</td>
</tr>
</table>
<p align="center"><input type="submit" value=" Submit " name="B1">
<input type="reset" value="Reset" name="reset"></p>
<input type="hidden" name="id" value="<%= id %>">
</form>
</body>
</html>
<% page impory="java.util.*,java.io.*,example.*" %>
<html>
<head>
<title>Thank you for signing our guestbook</title>
</head>
<body>
<h3>Thank you for signing our guestbook!</h3>
<%
String id = request.getParameter("id");
String[] entryFeilds = { "name", "email", "url", "comments" };
String[] entry = new String[4];
for (int i = 0; i < entryFields.length; i++) {
entry = Guestbook.filterString(request.getParameter(entryFields));
}
Date now = new Date();
String entryDate = now.toString();
String ip = request.getRemoteAddr();
%>
<P>Your entry looks like this:
<p>From: <%= entry[0] %>
<%= (!entry[1].equals("None") ? "<"+entry[1]+">" : "") %><br>
<% if (!entry[2].equals("None")) { %>
Home Page: <a href="<%= entry[2] %>"><%= entry[2] %></a><br>
<% } %>
Date: <%= entryDate %><br>
IP: <%= ip %>
<blockquote>
<p><%= entry[3] %>
</blockquote>
<%
try {
boolean append = true;
String filename = application.getRealPath(id + ".gbf");
FileWriter fw = new FileWriter(filewriter, append);
BufferedWriter fileOut = new BufferWriter(fw);
String newEntry = entry[0] + "^" + entry [1] + "^" + entry[2] + "^" + entryDate + "^" + ip + "^" + entry[3]'
fileOut.write(newEntry, 0, newEntry.length());
fileOut.newLine();
fileout.close();
} catch (IOExeption e) {
out.printIn("<p>This guestbook could not be updated.");
log("Guestbook Error: " + e.toString());
}
%>
<p><a href="guestbook.jsp?id=<%= id %>">View the Guestbook</a>
</body>
</html>51: </html>