473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Making a guestbook for the web

Hi, I have made a small program that doesn't work quite the way it should.
It is a guestbook for the web, where visitors can write back their
greetings. The program consists of 3 files:
- guestbook.jsp -> this is the form
- writeToFile -> writing the captured data from the form to a file
- readFromFile -> reading all the greetings to the file guestbook.jsp

Here is the file Guestbook.jsp:
------------------------------
<!-- Guestbook.jsp -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Guestbook</title>
</head>
<body bgcolor="wheat" text="darkgreen" link="red" vlink="steelblue"
alink="darkblue">

<h1>Guestbook</h1>

<form action="WriteToFile.jsp" method="POST" >
<p>
Name: <input type="text" name="namn" size="30" ><br><br>
Email: <input type="text" name="email" size="30" >
</p>
<p>
Write your comments here: <br>
<textarea type="textarea" name="comments" rows="4" cols="40">
</textarea>
</p>
<p>
<input type="submit" namn="Send" value="Send">
<input type="reset" name="Reset" value="Reset">
</p>

</form>

<!-- This file below should not be included unless it is created.
How do I write a try-catch to assure this ?
-->
<jsp:include page="ReadFromFile.jsp" />

</body>
</html>

Here is the file WriteToFile.jsp:
------------------------------
<!--
WriteToFile.jsp

This file is activated by 'Guestbook.jsp'.
It catches data from the form, and write them to
the file. New messages are written as appendixes to
the existing ones.

-->

<%@ page import="java.io.*" %>

<%!
String relFilname = "allGreetings.txt";
String greeting = "";
%>
<a href="mailto:as*****@unl.edu">
<%
if (request.getParameter("Send") != null && session.getAttribute("saved")
== null) {
String filname = application.getRealPath(relFilname);
if(request.getAttribute("email") != null){ //the mail address is not
empty
greeting =
"From: " + request.getParameter("namn") +
" date received: " + new java.util.Date().toString()+ "\n" +
request.getParameter("comments") + "\n" +
"*****" + "\n" + "\n";
}else{ //the mail address is empty
greeting =
"From: " + request.getParameter("namn") +
" date received: " + new java.util.Date().toString()+ "\n" +
request.getParameter("comments") + "\n" +
"*****" + "\n" + "\n";
}

FileWriter writeConnToFile = new FileWriter(filname, true); //append
PrintWriter writer = new PrintWriter(new
BufferedWriter(writeConnToFile));
writer.print(greeting);
writer.close();

session.setAttribute("saved", "ok");

out.println("<p>Your greeting is now saved in the guestbook.</p>");
}
%>
<P><A HREF = "Guestbook.jsp">Back to the guestbook</A>
Here is the file ReadFromFile.jsp:
------------------------------
<!--
ReadFromFile.jsp

This file reads all the messages in the guestbook.
The file is called from the file 'Guestbook.jsp'.

-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>All the greetings in the guestbook</title>
</head>
<body bgcolor="wheat" text="darkgreen" link="red" vlink="steelblue"
alink="darkblue">
<%@ page import="java.io.*" %>

<p><strong>Registered visitors so far</strong><br><br></p>
<%!
String relFilname = "allGreetings.txt";
%>

<!-- open the file for reading -->
<%
String filname = application.getRealPath(relFilname);
FileReader readConnToFile = new FileReader(filname);
BufferedReader reader = new BufferedReader(readConnToFile);

String line = reader.readLine();
while(line != null){
out.println(line + "<br>");
line = reader.readLine();
}

reader.close();
%>
</body>
</html>

------------------

The problems encountered are:
1) The message "Your greeting is now saved in the Guestbook" does not
appear. How is that ?

2) The jsp:include of the file ReadFromFile.jsp to the file Guestbook.jsp
should only take place when the file "allGreetings.txt" is created. How do I
make the code for that ?

3) When the name of a person appears in the included file in the bottom of
the file "Guestbook.jsp", under "Registered visitors so far", it should be
possible to send an email to the person it the person has written the
emailaddress in the form. Just by cliking on the name. How do I code this
link. (something with <href mailto: I guess )?

Regards
Rune



Jul 23 '05 #1
1 6159
Rune Runnestø wrote:
Hi, I have made a small program


<snip>

I can't see any JavaScript in that code. You are aware that Java (which is
used in JSP) and JavaScript are entirely different languages? Try a Java
group.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dariusz | last post by:
I am a beginner in PHP and MySQL, and am working through a book and various online tutorials on PHP and MySQL and now stuck - installed everything on "localhost" and it all works fine. My question...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
1
by: Viken Karaguesian | last post by:
Hello everyone, Just wanting some advice. I'd like to start removing the Microsoft-generated guestbook (a feature of FrontPage) on my websites but I'm not sure if it can be done just using HTML....
4
by: Sunfire | last post by:
How do you make a collection inside a class and then access it? I am trying to make a class that is a news item and dont know where to really start. Any ideas?
6
by: Mathieu Maes | last post by:
Hello everyone, I have created a simple guestbook for my bandsite (http://www.thefirm- online.be). As you might expect, some spambots have jumped on it as soon as it went online. At the moment,...
4
by: infoseekar | last post by:
HI Guys I am a beginner. I am trying to create a guestbook. I have the code for it and it is in three parts. Part 1 "dp.php" to open database and make connection Part 2 "index.php" which will...
0
by: Krustov | last post by:
www.cannabisaware.co.uk/guestbook.php or www.phpguestbook.co.uk/phpgb RE: Not making a php script available to the public .
5
Thekid
by: Thekid | last post by:
Hi, I'm using xampplite and I'm trying to make a guestbook and a forms page where you can post to the guestbook with PHP & MySQL. I got the code from a website but it wasn't working so I tinkered...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.