tags:

views:

448

answers:

2

FIRST.JSP

<jsp:useBean id="Bean" scope="session" class="Bean.Student_Enrollment_Bean" />
<jsp:setProperty name="Bean" property="*"/>

<tr>
    <td >Student First Name</td>
    <td>
    <% if( (Bean.getStudent_first_name()==null) || (Bean.getStudent_first_name().trim().length()==0) || Bean.getStudent_first_name().equals("null"))  {  %>
        <input type="text" name="student_first_name" >
    <% } else { %>
        <input type="text" name="student_first_name" value="<%=Bean.getStudent_first_name()%>">
    <%  } %>
    </td>
</tr>

SECOND.JSP

<jsp:useBean id="Bean" scope="session" class="Bean.Student_Enrollment_Bean" />
<jsp:setProperty name="Bean" property="*"/>

<tr> 
    <td >SSLC Name</td>
    <td>
    <% if( (Bean.getName_sslc()==null) || (Bean.getName_sslc().trim().length()==0) || Bean.getName_sslc().equals("null"))  {  %>
        <input type="text" name="name_sslc">
    <% } else { %>
        <input type="text" name="name_sslc" value="<%=Bean.getName_sslc()%>">
    <%  } %>
    </td> 
</tr>

JAVABEAN.JAVA

public class Student_Enrollment_Bean 
{

    private String student_first_name="";
    private String name_sslc;


    public String getStudent_first_name() {
        return student_first_name;
    }

    public void setStudent_first_name(String student_first_name) {
        this.student_first_name = student_first_name;
    }


    public String getName_sslc() {
        return name_sslc;
    }

    public void setName_sslc(String name_sslc) {
        this.name_sslc = name_sslc;
    }

}

Hi all above is my code.....i have problem with jsp session scope.....In first page i enter name as "first name" then i am going to second page, in this page i enter school name as "school name"....now i am going back to first page, in this(first) page the value("first name") is there in the text box what i typed...now i delete the value and i left that text field as blank and i am going to second page and then return to first page...here now i want the blank text field only....but it showing the value("first name") what i typed at first time. Pls Let me know what and where is the problem behind that code.

I dont want the logic by setting as a hidden variables or session.setAttribute. Pls Suggests me any other solution. Why the bean didnot get the value of empty string....?

Thanks in Advance....

A: 

You only use input tags in both pages without actually using a form tag to define clearly an action that your application should take whenever a user fills the textfields.

My advice would be to search google for how to use JSP and forms. Your JSP pages do not need to have if scriptlets as your solution shows.

See for example http://www.jsptut.com/Forms.jsp

kazanaki
A: 

The functional requirements are quite unclear, so I can't give a well suited answer.

But I can see that you've declared the jsp:useBean yourself to use the session scope. That's the actual problem. You seem to want to keep the data request scoped. In this case just change scope to request. You're already using jsp:setProperty with property="*", this would automagically put the request parameters in the bean based on the property names. Just make use of it wisely. Further on I would recommend to use Expression Language instead of those afwul scriptlets.

E.g.

<input type="text" name="student_first_name" value="${Bean.student_first_name}">

and then in the second.jsp pass it through as hidden parameter:

<input type="hidden" name="student_first_name" value="${Bean.student_first_name}">

That's all. And no, it won't print null when the actual value is null. That's the nice thing of EL.

That said, I would recommend to drop those PHP/C naming conventions and use real Java naming conventions. Variables shouldn't start with uppercase and you should use CamelCase.

BalusC