wood burning stoves 2.0*
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
Author

fileoutputstream in jsp is not working

p s Shetty
Greenhorn

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
index.jsp
<%@ page import="java.io.*" %>
<jsp:useBean id="blogs3" scope="session" class="blogs.Q3" />
<html>
<head>
<title>Author Result</title>
</head>
<body>
Blog Created<br>
<%= blogs3.doit() %><br>
</body>
</html>

And the java program is as follows
Q3.java
package blogs;
import java.io.*;
public class Q3
{
public static FileOutputStream out;
public static PrintStream p;
public static DataInputStream in = new DataInputStream(System.in);
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");
p.println(ab);
p.close();
return "abc";
}

}

This program above gives output as
blog created
abc

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: fileoutputstream in jsp is not working
 
Similar Threads
Problem with uploading images
Java
Servlet Displays Old DB Entries
Problem in OutputStream
servlet not found