Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Why can't I write to file inside a doGet() method?

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why can't I write to file inside a doGet() method?

    Hey, I've made a very simple java servlet in Eclipse and I wrote my own logging class which opens a file and writes to it.
    This logging class works fine, however when I tried to use it inside the doGet method of my servlet it wouldn't open the file and write to it but my servlet worked fine. Any ideas what's going on? The file is not even created either.

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
     
    		// TODO Auto-generated method stub
    		Enumeration en = request.getHeaderNames();
    		Object obj = null;
    		String temp = "";
    		while(en.hasMoreElements()){
     
    			obj = en.nextElement(); //gets name of header
    			temp = obj.toString();
    			temp = appender(temp);
    			response.getWriter().write(temp+request.getHeader(obj.toString()));
    			response.getWriter().println();
    		}
     
     
    		LogWriter.write("Why doesn't this stupid thing work???");
    		LogWriter.write("HELLO");
     
    	}

    Cheers


  2. #2
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why can't I write to file inside a doGet() method?

    I figure out the problem, I was missing the dependent class which did the writing from my web.xml file.

Similar Threads

  1. Calling method from .class file
    By alexx_88 in forum Java Theory & Questions
    Replies: 6
    Last Post: April 24th, 2012, 02:14 AM
  2. Writing in a file using Java
    By JavaPF in forum File Input/Output Tutorials
    Replies: 4
    Last Post: December 17th, 2011, 04:33 PM
  3. How to write 2 dimensional array of float numbers to binary file?
    By Ghuynh in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 17th, 2010, 04:26 PM
  4. How to write to specific part of an html file using java
    By nasi in forum File I/O & Other I/O Streams
    Replies: 12
    Last Post: May 27th, 2010, 11:22 PM
  5. write text to a file help
    By wolfgar in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: November 24th, 2009, 08:36 AM