This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

newbie question about servlets calling methods

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've written a class, Append.class, that has one method,
doAppend(String open, String write) that opens file "open" and adds a new line "write" to that file. if Append.class is in the same directory as a servlet i write, can the servlet create an Append object and call the doAppend() method of that object? here is all the code i am using, in this order:
Append.java: (what i am tryin to call from my servlet)


PassNgo.java (the servlet that should do the calling)

finally, the html page that gets the info

i would really appreciate any help, thanx
[This message has been edited by Eric Johnson (edited September 10, 2001).]
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In short, yes it is possible to do what you want.
Some comments....
- you don't need the main() method in the Append.java
- you need to import Append in your servlet.
- you are better of writing your own no argument constructor
for the Append class (a default is avail, but just good practice)
- your choice of varaibles "open" and "write" maynot a good
one, IMO anyways, these are method names in java so maybe confusing...

just a few of my thoughts....
- satya

 
Eric Johnson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx for the response. i still am having no luck appending my text file though. here is the new PassNgo servlet code:

and here is the new Append:

i hope someone can straighten me out, i am tired of feeling stupid, thanx
[This message has been edited by Eric Johnson (edited September 10, 2001).]
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure, but did you try
FileWriter toWrite = new FileWriter(fileReference, true);
?
 
Lookout! Runaway whale! Hide behind this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic