File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes fileoutputstream in jsp is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "fileoutputstream in jsp is not working" Watch "fileoutputstream in jsp is not working" New topic

fileoutputstream in jsp is not working

p s Shetty

Joined: Dec 28, 2012
Posts: 2
Hey, I have written a program in jsp which calls an external java program and requests for the creation of a text file as follows
<%@ page import="*" %>
<jsp:useBean id="blogs3" scope="session" class="blogs.Q3" />
<title>Author Result</title>
Blog Created<br>
<%= blogs3.doit() %><br>

And the java program is as follows
package blogs;
public class Q3
public static FileOutputStream out;
public static PrintStream p;
public static DataInputStream in = new DataInputStream(;
public static String a = "myfile.html";
public static StringBuffer ab = new StringBuffer();

public static void main(String args[])

public static String doit()throws Exception
out=new FileOutputStream(a);
p = new PrintStream(out);
System.out.println("Write now");
ab.append("adfdfdsdfdsfdsf fsdfsfsfsfsfsfdsffdfddfsdfs dffsdfssfsdfdsfbrcd");
return "abc";


This program above gives output as
blog created

But does not create a myfile.txt file.Please Help
The Q3 programm when individually compiled using javac creates the file very well. But does not works with jsp.
p s Shetty

Joined: Dec 28, 2012
Posts: 2
Hey, friends I have been trying to solve this problem from the last 4 days. But finally just after posting this i got the solution.
just a small editing in the Q3 made it possible
i just changed this line
public static String a = "C:/Program Files/Java/myfile.html";
Well just include the whole file path.
I agree. Here's the link:
subject: fileoutputstream in jsp is not working
It's not a secret anymore!