hi
heres the code you asked for. First it in parts of the struts-config that use the action and action form:
in the form bean defs:
<form-bean name="userForm"type="app.UserForm"/>
in the global forwards:
<forward name="confirmDetails"path="/confirmDetails.jsp" />
in the action-mappings
<actionpath="/adduser"
type="app.UserAction"
name="userForm"
scope="request"
input="/addDetails.jsp" >
</action>
THE FORM IS AS FOLLOWS:
package app;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class UserForm extends ActionForm {
private
String title = null;
private String firstName = null;
private String lastName = null;
private String email = null;
private String DOB = null;
public String getBirth() {
return DOB;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getTitle() {
return title;
}
public String getDOB() {
return DOB;
}
public void setEmail(String email) {
this.email = email;
}
public void setDOB(String DOB) {
this.DOB = DOB;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setTitle(String title) {
this.title = title;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(title == null || title.equals("")) {
errors.add("title", new ActionError("error.title"));
}
if(firstName == null || firstName.equals("")) {
errors.add("firstName", new ActionError("errors.firstName"));
}
if(lastName == null || lastName.equals("")) {
errors.add("lastName", new ActionError("errors.lastName"));
}
return errors;
}
}//End UserForm
AND THE ACTION IS:
package app;
import java.io.*;
import java.io.Writer.*;
import java.io.IOException;
import java.lang.StringBuffer.*;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class UserAction extends Action {
private String title = null;
private String firstName = null;
private String lastName = null;
private String email = null;
private String DOB = null;
private File file = new File("/home/nguy/blah.txt");
StringBuffer contents = new StringBuffer();
String line;
public String readFile(){
BufferedReader input = null;
try {
input = new BufferedReader( new FileReader(file) );
String line = null;
while (( line = input.readLine()) != null) {
contents.append(line);
contents.append(";");
}//end of while
}//end try
catch (FileNotFoundException ex) {
ex.printStackTrace();
}//end catch
catch (IOException ex) {
ex.printStackTrace();
}//end catch
return contents.toString();
}// end of readFile
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String newfile;
newfile = readFile();
String
doc;
doc = getDetails();
BufferedWriter output = null;
output = new BufferedWriter( new FileWriter(file) );
output.write(doc);
output.close();
return (mapping.findForward("confirmDetails"));
}
}//End of UserAction
i know there are a few bits of the above code that may not be needed but are included to let me
test the read/write functionality so i knew the problem wasn't there.
any help you can give would be great
nicola