accessing an array in a bean using servlets and jsp

i'm tryin g to set the values of a string array in a bean using a servlet and then get them from a jsp. But only null is returned. is this because the values are not prpperly set or is something wrong with th scriplet in the jsp file. any help is most appreciated. thankx

the bean, servlet and the jsp files ae given below.

//User.java

package beans;

publicclass User

{

privateint No_Of_Questions = 30;

private String name;

privateint result;

private String [] question =new String [No_Of_Questions];

private String [] answer =new String [No_Of_Questions*4];

public User(){}

publicvoid setName(String str){name = str;}

public String getName(){return name;}

publicvoid setResult(int marks){result = marks;}

publicint getResult(){return result;}

publicvoid setQuestion(String [] ques){question = ques;}

public String [] getQuestion(){return question;}

publicvoid setAnswer(String [] anws){answer = anws;}

}

//************************8jsp file

<%-- test.jsp --%>

<html>

<head><title>StudentRegistration Front</title></head>

<jsp:useBean id="user" class="beans.User" scope="session" />

<body>

<font color="blue">

<h2 align="center">

Welcome <jsp:getProperty name="user" property="name" />:

</h2>

</font>

<%

//String name = user.getName();

String [] question = user.getQuestion();

String [] answer = user.getAnswer();

out.println(question[1]);

%>

<form action="marking.jsp" method="post">

<h4 align="center">

<input type="submit" value="submit">

</h4>

</form>

</font>

</body>

</html>

//***************************servlet

ResultSet questionSet = statement.executeQuery("SELECT QUESTION FROM QUESTION");

ResultSet answerSet = statement.executeQuery("SELECT ANSWER FROM ANSWER");

while(questionSet.next())

{

for(int i = 1; i<=noOfQuestions; i++)

question[i] = questionSet.getString(i);

}

while(answerSet.next())

{

for(int j = 1; j<=noOfAnswers; j++)

answer[j] = answerSet.getString(j);

}

user.setQuestion(question);

user.setAnswer(answer);

when the webapp is run using tomcat, null is printed. plz help

[4737 byte] By [cadiiia] at [2007-11-27 1:55:36]
# 1
and the other thing is the name is printed. the code used to set the name is asUser user = new User();user.setName(name);only the question is not printed also the answers.
cadiiia at 2007-7-12 1:28:46 > top of Java-index,Java Essentials,New To Java...
# 2

question[i] = questionSet.getString(i);

Try:

question[i] = questionSet.getString(1);

Or better still:

question[i] = questionSet.getString("QUESTION");

or "ANSWER" for the anser record set.

ResultSet.getString(int) looks up the value in a column (starting at index 1) in a result set.

getString(String) looks up the value in a column by column name.

TimSparqa at 2007-7-12 1:28:46 > top of Java-index,Java Essentials,New To Java...