Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

servlets and guestbook

Status
Not open for further replies.

summi

Technical User
Sep 19, 2001
10
IN
hello
I am trying to run guestbook with the help of servlets.Servlet get the parameters of textfield and write those parameters in html file with the help of streams.I can run this servlet successfully when i give a path like"c:/guestbook.html".But same servlet does not work with tomcat when i give path as" to the location of file.It also does not give any error. Just entries are not there. part of the servlet is like this:

try {
BufferedReader in4 =new BufferedReader(new StringReader(s2));
PrintWriter out1 =new PrintWriter(new BufferedWriter(new FileWriter(" true)));
Can anybody suggest me the possible cause.Any help will be highly appreciated.
Smriti
 
Well, there are a few things wrong with your approach.

First of all, having a servlet try to write to a URL context is somewhat off the mark. Also, I don't see any of the code where you actually write to the file. It'd help to see the rest of your code.

Usually in Tomcat, a webapp is in it's own context, say 'guestbook'. Putting things in the root context requires more planning then you have probably done. Therefore, it is more likely that you would want to do something like:


You will have to setup the server.xml or create a deployment descriptor to do this.

In reality, however, you are better off using servlets to write to and present the HTML page dynamically, not having the servlet rewrite the HTML page each time you add a guestbook entry.

For an example of how to do this, check out MY guestbook @
I wrote this using a combination of JSP and servlets. The servlet is simply a controller. The JSP's do the actual presentation work. Check out the web for the MVC (Model View Controller) pattern.

Regards,

Charles
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top