Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 19th, 2002, 08:31 PM
peter83 peter83 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 19 peter83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Writing to a text file

I need to know how i can capture the user input and then write to a text file. Currently, the form page is saved as Adhoc.jsp, which means that the form page uses jsp to retrieve some information from the database.

*Note: i just need to know how i can capture the user input and then write to a text file.

Pls help asap...........

Reply With Quote
  #2  
Old August 20th, 2002, 12:12 PM
midntrdr midntrdr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 45 midntrdr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
look at getParameter and FileOutputStream

Reply With Quote
  #3  
Old August 24th, 2002, 04:28 PM
CharlesBell CharlesBell is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Vicksburg, MS
Posts: 7 CharlesBell User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Use a bean to do the file writing as in:

<%@ page language="java" contentType="text/html" import="java.util.*" %>
<%@ page errorPage="errorPage.jsp" %>


<html>
<!-- RequestWriter.jsp executed on <%= (new java.util.Date()) %> -->
<head>
<title>RequestWriter</title>
</head>
<body bgcolor="#669966" >
<jsp:useBean id="writer" scope="page" class="utilities.RequestWriter" />
<jsp:setProperty name="writer" property="*"/>
<%

String password = request.getParameter("password");

if (writer.isCorrectPassword(password)) {
writer.save();
out.println("<h2 align=\"center\">Changes saved</h2>");
}else{
out.println("<h2 align=\"center\">Incorrect Password</h2>");
}

%>


<form action="index.jsp" method="get">
<center><input type="submit" value="Go to Home Page"/></center>
</form>

</body>
</html>

***************************
/* RequestWriter.java
* @author: Charles Bell
* @version: August 24, 2002
*/
package utilities;

import java.io.*;
import java.util.*;

/**
*/
public class RequestWriter extends Object implements Serializable {

private String id = "";
private String item = "";
private String responsibility = "";
private String type = "";
private String notes = "";
private String completionDate = "";
private String status = "";

private String root = "/usr/local/etc/httpd/sites/abc.com/htdocs/WEB-INF/requestfolder";


public String getID(){
return id;
}

public String getItem(){
return item;
}

public String getResponsibility(){
return responsibility;
}

public String getType(){
return type;
}

public String getNotes(){
return notes;
}

public String getCompletionDate(){
return completionDate;
}

public String getStatus(){
return status;
}


public void setID(String s){
id = s;
}

public void setItem(String s){
item = s;
}

public void setResponsibility(String s){
responsibility = s;
}

public void setType(String s){
type = s;
}

public void setNotes(String s){
notes = s;
}

public void setCompletionDate(String s){
completionDate = s;
}

public void setStatus(String s){
status = s;
}

/** Returns a complete string description of this Bug.
*/
public String toString(){
return "ID: " + getID() + "\n"
+ "Item: " + getItem() + "\n"
+ "Responsibility: " + getResponsibility() + "\n"
+ "Type: " + getType() + "\n"
+ "Notes: " + getNotes() + "\n"
+ "CompletionDate: " + getCompletionDate() + "\n"
+ "Status: " + getStatus();
}



/** Wrtes this Request Data to a text file in the requestfolder folder.
*/
public void save(){
try{
File file = new File(root, getID() + ".txt");
FileWriter fw = new FileWriter(file);
fw.write(toString());
fw.close();
}catch(FileNotFoundException fnfe){
System.err.println("FileNotFoundException: " + fnfe.getMessage());
}catch(IOException ioe){
System.err.println("IOException: " + ioe.getMessage());
}
}

/** Returns the current date-time String.
*/
private String getTimeString(){
return Calendar.getInstance().getTime().toString();
}

public boolean isCorrectPassword(String password){
return (password.compareToIgnoreCase("changeisgood") == 0);
}

}

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Writing to a text file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway