hi!
i m trying to write some user entered entries to a text file on server...
here is my code

String news=new String();
        String path=application.getRealPath("news.txt");
news=request.getParameter("news");
  PrintWriter pw = new PrintWriter(new FileOutputStream(path));
    pw.println(news);
    pw.close();

this just doesnt seem to work....can anyone help?News is a text are field on the page

Recommended Answers

All 3 Replies

I didn't find any problem with this code.

<%@ page language="java" import="java.io.*"%>

<%
String news=request.getParameter("news");
String cmd=request.getParameter("cmd");
if(cmd==null) cmd="";
if(cmd.equals("Submit")) {
   String path=application.getRealPath("news.txt");
    PrintWriter pw = new PrintWriter(new FileOutputStream(path));
    pw.println(news);
    pw.flush();
    pw.close();
  }
%>
<form method="post" action="page1.jsp">
 <textarea col="40" row="5" name="news"></textarea>
 <input type="submit" name="cmd" value="Submit"/>
</form>

hi!
thanx for replying....i later tried my code by creating a java class and executed it at the command prompt it seems to work fine....
but when i use the same code in netbeansIDE 6.1 with glassfish app server...it just does nothing.....can neone suggest possible reasons for this.....anything that the environment is missing or i should add..
i know it is a very specific query but i really need a solution on the same platform only.
thanx and regards

sry mentioned the wrong version it 's netbeans 6.5.1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.