• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting nulls writing file

 
Adam Teg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP and a User class. All the variables are being populated. I checked but when I instanciate the User class and do a user.get I get nulls for everything but email, last name and first name. Even these are not in the order I excepted.

Can you help?

<%!
public synchronized void addRecord(User user, String filename)
throws IOException{
PrintWriter out = new PrintWriter(
new FileWriter(filename, true));
out.println(user.getEmailAddress()+ ","
+ user.getFirstName() + ","
+ user.getLastName() + ","
+ user.getfirstLifeStory() + ","
+ user.getheardFrom() + ","
+ user.getlistChoice1() + ","
+ user.getfirstLifeStory1() + ","
+ user.getheardFrom1() + ","
+ user.getlistChoice11());
out.close();
}
%>
<%
String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
String emailAddress = request.getParameter("emailAddress");
String firstLifeStory = request.getParameter("firstLifeStory");
String heardFrom = request.getParameter("heardFrom");
String listChoice1 = request.getParameter("listChoice1");
String firstLifeStory1 = request.getParameter("firstLifeStory1");
String heardFrom1 = request.getParameter("heardFrom1");
String listChoice11 = request.getParameter("listChoice11");

User user = new User(emailAddress,firstName,lastName,firstLifeStory,heardFrom,listChoice1,firstLifeStory1, heardFrom1,listChoice11);

addRecord(user, "etc/UserInput.txt");
{
out.println("<table align=\"center\" width=\"80%\">");
out.println("<tr><td align=\"center\"><strong>Thank You</strong></td>");
out.println("</table>");
}
%>
/*******************
USER CLASS
/****************

public class User
{
private String firstName, lastName, emailAddress;
private String fLS, hF, lC1;
private String fLS1, hF1, lC11;

public User(){}

public User(String email, String first, String last, String firstLifeStory, String heardFrom, String listChoice1, String firstLifeStory1, String heardFrom1, String listChoice11)
{
firstName = first;
lastName = last;
emailAddress = email;
fLS = firstLifeStory;
hF = heardFrom;
lC1 = listChoice1;
fLS1 = firstLifeStory1;
hF1 = heardFrom1;
lC11 = listChoice11;
}
public void setfirstLifeStory(String firstL){fLS = firstL;}
public void setheardFrom(String h){hF = h;}
public void setlistChoice1(String l1){lC1 = l1;}
public void setfirstLifeStory1(String firstL1){fLS1 = firstL1;}
public void setheardFrom1(String h1){hF1 = h1;}
public void setlistChoice11(String l11){lC11 = l11;}
public void setFirstName(String f){firstName = f;}
public void setLastName(String l){lastName = l;}
public void setEmailAddress(String e){emailAddress = e;}

public String getLastName(){return lastName;}
public String getEmailAddress(){return emailAddress;}
public String getFirstName(){return firstName;}
public String getfirstLifeStory(){ return fLS; }
public String getfirstLifeStory1(){ return fLS1; }
public String getheardFrom(){ return hF; }
public String getheardFrom1(){ return hF1; }
public String getlistChoice1(){ return lC1; }
public String getlistChoice11(){ return lC11; }
}
/***********************
OUTPUT
/***********************
Smith,as@as.com,Adam,null,null,null,null,null,null
[ February 23, 2006: Message edited by: Bear Bibeault ]
 
Jherald Lacambra
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you use multipartform on the enctype of the form you have submmited?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jherald Lacambra:
do you use multipartform on the enctype of the form you have submmited?


What does that have to do with the question?
 
Jherald Lacambra
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im also experienced getting null when i use enctype="multipart/form-data" in the form that i submitted with file element.. what i did is i separate the form with the file element from the form with text and hidden fields.. and submit the two forms. now i get all the values of the hidden and text fields and the file object
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see. Yes, with a multi-part request, getParameter will not work at all since the request object will not parse request data that does not have an enctype of 'application/x-www-form-urlencoded' (which is the default for the HTML form tag).

This is why 3rd-party libraries are usually used for file uploading that know how to parse the multi-part request format.
[ February 23, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With regards to the original question, from the code that is posted (I'm currently biting my tongue with regards to the presence of so much Java code in a JSP page), I'd have to say that the problem is with the posting code. Have you verified that the URL being submitted contains all the request parameters as expected (if a GET), or that the form contains all the expected elements (if a POST)?
[ February 23, 2006: Message edited by: Bear Bibeault ]
 
Adam Teg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I have verified getParam works.

So to rephrase my question. How can I send this to the file writer with out using the User Class? In essence put the variable out to the filewritter.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea what you mean by that.
 
Adam Teg
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to put the getParam in...long story but I got it.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic