File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes newbie question about servlets calling methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "newbie question about servlets calling methods" Watch "newbie question about servlets calling methods" New topic
Author

newbie question about servlets calling methods

Eric Johnson
Ranch Hand

Joined: Apr 30, 2001
Posts: 49
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).]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

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


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Eric Johnson
Ranch Hand

Joined: Apr 30, 2001
Posts: 49
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).]
Mahesh Rana
Ranch Hand

Joined: Sep 05, 2001
Posts: 139
I am not sure, but did you try
FileWriter toWrite = new FileWriter(fileReference, true);
?


SCJP2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newbie question about servlets calling methods
 
Similar Threads
The requested method POST is not allowed for the URL
cookie setDomain problem.
Need help. Can a servlet do this?
tomcat can't find index.jsp
problem executing the servlet